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单击操作,类按钮也有一个绑定它的点击操作。问题是,当我点击按钮时,它还会触发标题栏点击操作。如何使点击不传播?
答案 0 :(得分: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;
}
}