我有以下代码:

<a id="clickme" href="#">
    <span>Text for link goes here</span>
    <button id="deleteme">X</div>
</a>


和以下javascript:

$("body").on('click', "#clickme", function(e) {
  //stuff here
});


$("body").on('click', "#deleteme", function(e) {
  //stuff here
});


如何使我单击#deleteme时,单击#clickme的click事件不会运行?

最佳答案

使用stopPropagation

$("body").on('click', "#deleteme", function(e) {
  e.stopPropagation();
});

08-19 05:45