在子div中也可以在父div中单击

时间:2014-03-04 11:22:01

标签: javascript html5 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()方法也会被触发,我怎么能这样做,如果我点击弹出窗口就会触发弹出窗口?

1 个答案:

答案 0 :(得分:32)

执行此操作是因为<td>嵌套在<tr>中,然后点击首先触发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>