我有一个表行,单击它会触发一个事件。行内有(未显示)复选框及其样式标签。
我想要的是阻止(我猜是 :not 或 .not() 但无法弄清楚)单击复选框/标签时的执行。
HTML:
<center>
<table>
<tr class='pend'>
<td><input type="checkbox" id="bb"/> <label for="bb">X</label></td>
<td> </td>
<td>some text</td>
</tr>
</table>
</center>
CSS:
center {
margin-top:20px;
}
input[type=checkbox] + label {
width:10px;
height:10px;
background-color:red;
}
input[type=checkbox] {
display:none;
}
table tr {
height:40px;
background-color:gray;
}
table td {
padding:5px;
}
JS:
$('.pend').on('click',function(){
$(this).append('text');
return false;
})
JSFIDDLE:http://jsfiddle.net/ySuGB/2/
最佳答案
您需要防止单击复选框/标签时发生事件冒泡。
见下文,
// V-- Is the TD containing the checkbox and the label.
$('.pend :checkbox').parent().on('click', function(event) {
event.stopPropagation()
});
关于javascript - 单击时触发事件(复选框+标签除外),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12432301/