我用这个功能使我的表行可以点击
$("#grid tbody tr").click(function () { var $checkBox = $(this).find(':checkBox'); $checkBox.attr('checked',!$checkBox.attr('checked')); });
它工作正常,但是当我尝试单击复选框自己,它不工作。
我应该怎么做才能使他们工作?
解决方法
使用单个事件处理程序:
$("#grid tbody tr").click(function(e) { if (e.target.type == "checkBox") { // stop the bubbling to prevent firing the row's click event e.stopPropagation(); } else { var $checkBox = $(this).find(':checkBox'); $checkBox.attr('checked',!$checkBox.attr('checked')); } });
http://jsfiddle.net/karim79/UX2Fv/
@H_301_7@ @H_301_7@