2015-04-01 71 views
1

我有一個單擊事件附加到錶行和列內我有複選框。錶行單擊事件和複選框

<table> 
    <tbody> 
     <tr class='shop_order_single_table'> 
      <td><input type='checkbox' /></td> 
      <td><input type='checkbox' /></td> 
      <td><input type='checkbox' /></td> 
     </tr> 
    </tbody> 
</table> 

當我點擊複選框時,該行的click事件仍然執行。

這裏是我的代碼:

 $(".shop_order_single_table").on("click",function() { 
    //click event executes 
       }); 

我如何對錶行點擊複選框時不執行的單擊事件?

+0

http://stackoverflow.com/questions/9183381/how-to-have-click-event-only-fire-on-parent-div-not-children – Jordumus 2015-04-01 12:33:20

+0

請參見[「的問題是否應包含「標籤「?」](http://meta.stackexchange.com/questions/19190/should-questions-include-tags-in-their-titles),其中的共識是「不,他們不應該」! – 2015-04-01 13:28:12

回答

1
$(".shop_order_single_table input").on("click", function(e) { 
    e.stopPropagation(); 
}); 

$(".shop_order_single_table").on("click", function(e) { 
    // Your code 
}); 
+0

我試過了,點擊事件仍然執行? – user892134 2015-04-01 12:38:53

+0

@ user892134嘗試更新的代碼 – 2015-04-01 12:42:26

+0

謝謝,更新代碼的作品! – user892134 2015-04-01 12:44:13

相關問題