jQuery Children选择器问题

Jam*_*ers 4 javascript jquery

我有以下代码:

$("#Table1 tbody").children().each(function(e){
$(this).bind('click', 
            function(){
                // Do something here
            }, 
            false) 
});
Run Code Online (Sandbox Code Playgroud)

Table1 html表有2列; 一个用于名称,一个用于<button>元素.

当我点击表格行时,它工作正常.当我点击按钮时,按钮代码触发; 但是,行代码也是如此.

如何过滤选择器以使按钮不会触发父元素的单击事件?

cgp*_*cgp 7

这就是你想要的.

这是stopPropogation将停止父母.

<table>
  <tr>
    <td>The TD: <input type="button" id="anotherThing" value="dothis"></td>
  </tr>
</table>

<div id="results">
  Results:
</div>

<script>

  $(function() {
    $('#anotherThing').click(function(event) {
       $('#results').append('button clicked<br>');
       event.stopPropagation();       
    });
    $('td').click(function() {
       $('#results').append('td clicked<br>');

    });
  });

</script>
Run Code Online (Sandbox Code Playgroud)

这是一个工作示例的链接:

http://jsbin.com/uyuwi

你可以在http://jsbin.com/uyuwi/edit修补它