.html
<div class="col col-50"
ng-repeat="col in row"
ng-click="openProductDetails(col.prod_id);">
<button
ng-click="addToCart(col.prod_id);">
Add to cart
</button>
</div>
如你所见,我有一个 grid
或 <div>
这里是openProductDetails()
点击事件。在网格内部,我有一个 button
它有一个 addToCart()
.问题是当我点击按钮时,openProductDetails()
也被触发。单击按钮时,我找不到阻止父元素单击事件的方法。
提前致谢。
最佳答案
你可以使用 event.stopPropation()
。这个变量是对 JS 事件对象的引用,可以用来调用 stopPropagation()
<div class="col col-50"
ng-repeat="col in row"
ng-click="openProductDetails(col.prod_id);">
<button
ng-click="addToCart(col.prod_id); $event.stopPropagation();">
Add to cart
</button>
</div>
关于html - AngularJS - 带有 ng-click 事件的网格中包含的按钮单击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43152855/