$(table).click(function(){
alert(1)
})
$(table tbody tr).click(funtion(){
alert(2)})
这样子只会alert(1) 不会弹出2 有啥办法让他们都执行吗
tr点击事件也是table点击的时间 直接用:
$(table tbody tr).click(funtion(){
alert(1);
alert(2);
}),
一个单击一个为双击,就是将tr click写在table click里面,不过要判断第二次点击和第一次点击之间的时间差
table tbody tr 把他换成具体的标签
题主的代码是:
$(table).click(function(){
alert(1)
})
$(table tbody tr).click(**_funtion_**(){
alert(2)})
tr单击事件的function错了.所以tr的单击事件未生效.
所以.正确的代码应该是:
$("table").click(function(){
alert()
});
$("table tbody tr").click(function(){
alert(2)
})
如果我理解的没有错的话,你应该是想阻止冒泡事件,那么应该在子元素中添加代码.修改后的代码:
$("table tbody tr").click(function(e){
e.stopPropagation();
alert(2)
});
$("table").click(function(){
alert(1);
});
参考网址:https://www.cnblogs.com/jams742003/archive/2009/08/29/1556187.html
//简单,阻止子元素冒泡反应就可以了,如下,拷贝替换原来的tr事件
$(table tbody tr).click(funtion(e){
e.stopPropagation();//阻止冒泡
alert(2);
})
$("table").on("click",function(){
alert(1);
});
$("table body tr").on("click",function(){
alert(2);
});
try