最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Table Row onClick Overriding Checkbox - Stack Overflow

programmeradmin4浏览0评论

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!

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!

Share Improve this question asked Jun 1, 2011 at 19:21 sichinumisichinumi 1,8753 gold badges22 silver badges40 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 7

Take a look at 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.

发布评论

评论列表(0)

  1. 暂无评论