从事件监听器OnClick中排除按钮
16lz
2021-01-22
Really simple jquery question here that I have yet to resolve. I have the following html table
我还没有解决这个简单的jquery问题。我有下面的html表格
<table id="table-1">
<tr>
<td>Value 1</td>
<td>Value 2</td>
<td>
<button id="btn-1" value="Go"></button>
</td>
</tr>
</table>
I have the following event listener for when the table row is clicked
当单击表行时,我有以下事件监听器
$("table-1 tr").on(
'click',
function(e){
if(button was clicked){
//do some stuff
} else {
//do different stuff
}
}
);
I'd like this event listener to fire whenever the table row is selected, except for when the clicked item is my button. I've been trying to use :not
and .not()
, but no luck. Any ideas?
当选择表行时,我希望这个事件监听器可以触发,但是当单击的项是我的按钮时除外。我一直试着用:不,不是(),但没有运气。什么好主意吗?
4 个解决方案
#1
3
Based off your example where you want to catch the element type.
基于要捕获元素类型的示例。
$("#table-1 tr").on('click', function (e) {
var elementType = $(e.target).prop('nodeName');
if (elementType == 'BUTTON') {
console.log('buttonClick');
} else {
console.log(elementType);
};
});
http://jsfiddle.net/ymy9cn71/
http://jsfiddle.net/ymy9cn71/
更多相关文章
- jQuery -添加活动类并在单击时从其他元素中删除活动类
- 确定焦点事件:单击或tabstop
- 单击文件输入后,Fancybox正在关闭
- 如何使用jQuery捕获对href值的单击
- 单击列表项时如何编写内容? [重复]
- 如何通过多次单击在画布上显示多个箭头
- 单击链接中的复选框会导致以下链接——我如何避免这种情况?
- 我无法理解为什么我的代码中的单击选择文本
- 当锚标记被单击时,角值从一个页面传递到另一个页面