javascript - 在子 div 中也单击父 div

标签 javascript html angularjs twitter-bootstrap

我有以下代码:

        <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/

相关文章:

javascript - HTML 类型 ="search"检测清除按钮支持

javascript - 奇怪的 jQuery 文本框问题

angularjs - 单选按钮中的 ng-click 未被调用

angularjs - Angular 模型的依赖属性

Javascript 函数不打开嵌套可折叠

javascript - 等待 openCursor 在 IndexedDB 中完成

java - 从 Jar 调用 HTML 文件

linux - 在 Linux box 中使用 IE 启动器在 grunt 中运行 Karma

javascript - 如何在 Angular 7中的一个ngfor下将两个不同插值中的值相乘

java - onKeyUp Texftield 自动生成。 HTML/JAVA