Making a Table Row clickable

前端 未结 14 1038
悲&欢浪女
悲&欢浪女 2020-12-24 12:49

I wonder what the best way to make an entire tr clickable would be?

The most common (and only?) solution seems to be using JavaScript, by using onclick=\"javascript:

14条回答
  •  温柔的废话
    2020-12-24 12:59

    I have found this solution which works quite well:

    $(document).ready(function() {
        $('#example tr').click(function() {
            var href = $(this).find("a").attr("href");
    
            if(href) {
                window.location = href;
            }
        });
    });
    

    Just don't forget to style the cursor as a pointer on tr:hover

    #table tr:hover {cursor: pointer;}
    

    Source: http://www.electrictoolbox.com/jquey-make-entire-table-row-clickable/

提交回复
热议问题