how to make a whole row in a table clickable as a link?

前端 未结 26 2094
粉色の甜心
粉色の甜心 2020-11-22 14:05

I\'m using Bootstrap and the following doesn\'t work:


    
        
            Blah Blah
           


        
26条回答
  •  时光说笑
    2020-11-22 14:21

    You can add the button role to a table row and Bootstrap will change the cursor without any css changes. I decided to use that role as a way to easily make any row clickable with very little code.

    Html

    Cell 1 Cell 2 Cell 3

    jQuery

    $(function(){
         $(".table").on("click", "tr[role=\"button\"]", function (e) {
              window.location = $(this).data("href");
         });
    });
    

    You can apply this same principle to add the button role to any tag.

提交回复
热议问题