简体   繁体   English

表行 onClick 覆盖复选框

[英]Table Row onClick Overriding Checkbox

I'm having some issues with checkboxes in a table being "overridden" by the onClick attribute of the table row they are placed in.我在表格中的复选框被放置在其中的表格行的 onClick 属性“覆盖”时遇到了一些问题。

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.我有一列带有复选框作为表格的最左侧列,并且我还为每个表格行定义了一个 onClick function。 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).结果,当我单击任何复选框时,表格行的 onClick function 将触发(尽管该复选框仍被正确单击)。

Is there any way I can work around this?有什么办法可以解决这个问题吗? Having the table row's onClick only register for the other columns, for example?例如,让表格行的 onClick 仅注册其他列? (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!提前致谢!

Take a look at event.stopPropagation()看看 event.stopPropagation()

event.stopPropagation event.stopPropagation

You'll want to call this in your checkbox click handler.您需要在复选框单击处理程序中调用它。

$('.columnClass').click(function(e){
     if(this == e.target){
      //do things
 }

}) })

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.提供更多建议的代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM