0
I have the following html:

<div class="title-block">
    <span class="date">Apr 09, 2013</span>
    <span class="invoice">Invoice #1365512756</span>
    <span class="retail-price">Rp 270000</span>
    <span class="arvo-regular button green confirm-payment" data-id="2">Confirm Payment</span>
    <img src="/bundles/shopiousmain/img/dashboard-li-down-arrow.png">
</div>

类标题块有一个与之相关的 javascript 点击动作,类按钮也有一个与其相关的点击动作。问题是当我点击按钮时,它也会触发标题栏点击动作。如何使点击不会传播?

4

1 回答 1

1

如果您使用的是 jquery,则类似这样的东西

$("#buttonClass").click(function(e) {
   // mouse click on button
   e.stopPropagation();
});

JS

function doSomething (e) {
  var event = e || window.event;
  if (event.stopPropagation) {
    event.stopPropagation();
  } else {
    event.cancelBubble = true;
  } 
}
于 2013-04-15T11:27:01.500 回答