表行 onClick 覆盖复选框
我遇到了一些问题,表中的复选框被它们所在的表行的 onClick 属性“覆盖”。
我有一个包含复选框的列作为表的最左边的列,并且我还定义了一个 onClick 函数对于每个表行。因此,当我单击任何复选框时,表行的 onClick 函数就会触发(尽管该复选框仍然被正确单击)。
有什么办法可以解决这个问题吗?例如,让表行的 onClick 仅注册其他列? (不幸的是,我不知道如何实现它,但这是我能想到的第一个解决方案。)
提前致谢!
I'm having some issues with checkboxes in a table being "overridden" by the onClick attribute of the table row they are placed in.
I have a column with checkboxes as the leftmost column of a table, and I also have an onClick function defined for each table row. As a result, when I click any of the checkboxes, the onClick function of the table row triggers (though the checkbox is still clicked correctly).
Is there any way I can work around this? Having the table row's onClick only register for the other columns, for example? (I have no clue how the implementation of that would work, unfortunately, but that's the first solution I can think of.)
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
看一下 event.stopPropagation()
event.stopPropagation
你会想在其中调用它您的复选框点击处理程序。
Take a look at event.stopPropagation()
event.stopPropagation
You'll want to call this in your checkbox click handler.
这
只会在实际单击的是列而不是复选框时执行您的单击处理程序。
})
This will only execute your click handler when it's actually the column that's being clicked, not the checkbox.
一些代码会有帮助。复选框和按钮上的名称可能存在复制/粘贴错误。提供代码以获取更多建议。
some code would be helpful. May be copy/paste error with name on checkbox and button. Provide code for more suggestions.