This question already has answers here:
How to disable parent ng-click?

(2个答案)


3年前关闭。




我有下一个html:
<div class="parent"
         ng-click="ParentClick()">
    .
    .
    .
    <div class="child" ng-click="ChildClick()">
       Some Text
    </div>
</div>

因此,当我单击Some Text时,我有两个方法调用:ParentClick(), ChildClick()。当我以CSS方式单击ParentClick()时,是否可以禁用Some Text事件?

最佳答案

在单击ChildClick()时,您要运行event.stopPropagation(),以防止click事件冒泡DOM树

function ChildClick() {
    event.stopPropagation()
    ....
}

如果您有ChildClick$scope函数部分,则可以将$event传递给该函数并在内部使用它:
<div class="child" ng-click="ChildClick($event)">
</div>

$scope.ChildClick = function ($event) {
    $event.stopPropagation();
    ...
};

关于javascript - 在父div中禁用ng-click ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45842958/

10-10 13:08