1

I've got this javascript code and some tr elements inside a table, but the click event simply doesn't work on this element, I've already tried on other elements, such as div, and it worked. Does anybody know why?

$(document).ready(function() {
    $('tr').bind('click',function(){
    alert('clicked');
    });
});
4

1 回答 1

2

也许,尝试替代 click 或 on 方法。看看这些代码:

// With click
$(function() {
    $('tr').click(function(){
        alert('clicked');
    });
});

// With on
$(function() {
    $(document).on('click', 'tr', function(){
        alert('clicked');
    });
});

还要检查您的 tr 是否像这样可见:

$(function() {
    if($('tr').is(':visible')) {
        alert('visible');
    }
});
于 2013-07-18T19:39:18.640 回答