我有以下代码:
<table class="table">
<tr>
<th>Name___</th>
</tr>
<tr ng-repeat="app in apps"
ng-click="go('/editApp/' + plugin.name);">
<td>
<span>{{app.name}}</span>
</td>
<td style="width: 100px;">
<i class="glyphicon glyphicon-pencil"
ng-click="openPopup(app)"></i>
</td>
</tr>
</table>
当我点击 OpenPopup 时,也会触发 go() 方法,我该怎么做,如果我点击弹出窗口,只会触发弹出窗口?
最佳答案
执行此操作是因为您的 <td>
嵌套在 <tr>
, 然后点击 first first fired openPopup()
然后解雇 go()
.您可以使用 $event.stopPropagation()
停止事件传播到 <tr>
.
尝试
<table class="table">
<tr>
<th>Name___</th>
</tr>
<tr ng-repeat="app in apps"
ng-click="go('/editApp/' + plugin.name);">
<td>
<span>{{app.name}}</span>
</td>
<td style="width: 100px;">
<i class="glyphicon glyphicon-pencil"
ng-click="openPopup(app);$event.stopPropagation()"></i>
</td>
</tr>
</table>
关于javascript - 在子 div 中也单击父 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22170558/