Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/455.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何取消选中复选框,但阻止任何事件被触发?_Javascript_Jquery_Angularjs_Checkbox - Fatal编程技术网

Javascript 如何取消选中复选框,但阻止任何事件被触发?

Javascript 如何取消选中复选框,但阻止任何事件被触发?,javascript,jquery,angularjs,checkbox,Javascript,Jquery,Angularjs,Checkbox,我有一个onclick函数附加到复选框(选择或取消选择所有相关复选框),我使用的是AngularJs。因此,对于复选框X,有更多的依赖复选框a、B、C。因此,当所有的复选框都被选中时,X会被自动选中。甚至当其中一个被取消勾选时,X也被取消勾选。但我需要阻止“取消选中复选框事件”被解雇 有没有办法做到这一点 <span style="float: right"> <input id="SelectAllRecords" type="checkbox" ng-model="

我有一个onclick函数附加到复选框(选择或取消选择所有相关复选框),我使用的是AngularJs。因此,对于复选框X,有更多的依赖复选框a、B、C。因此,当所有的复选框都被选中时,X会被自动选中。甚至当其中一个被取消勾选时,X也被取消勾选。但我需要阻止“取消选中复选框事件”被解雇

有没有办法做到这一点

<span style="float: right">
    <input id="SelectAllRecords" type="checkbox" ng-model="toSelectAllEmployees"
           ng-click="selectAndAddAllEmployees($event)">{{selectAllLabel}} {{totalRecord()}}
</span>

$scope.$watch('toSelectAllEmployees',function() {
    // toSelectAllEmployees is an ng-model for select all Emp 
    if($scope.toSelectAllEmployees!=null && $scope.toSelectAllEmployees!=undefined) {   
        $scope.selectAllOrUnselectAll();
    }
});

$scope.selectAllOrUnselectAll = function() {   
    if($scope.toSelectAllEmployees!=null && $scope.toSelectAllEmployees!=undefined) {   
        if($scope.toSelectAllEmployees==true) {   
            $('.allEmployees').attr("checked", true);
        } else {
            $(".allEmployees").attr('checked',false);
            if($rootScope.fromMovingPage!=2 && $rootScope.fromMovingPage!=3) {
                // as we have now unchecked all employees hence we need to do matching and selected employee list size 0
                $scope.matchingAndSelectedEmployeesList.length = 0;
            }
        }
    }
}

{{selectAllLabel}{{totalRecord()}}
$scope.$watch('toSelectAllEmployees',function(){
//ToSelectalEmployees是选择所有Emp的ng模型
如果($scope.toSelectAllEmployees!=null&$scope.toSelectAllEmployees!=未定义){
$scope.selectAllorRunSelectAll();
}
});
$scope.selectAllOrUnselectAll=函数(){
如果($scope.toSelectAllEmployees!=null&$scope.toSelectAllEmployees!=未定义){
如果($scope.toSelectAllEmployees==true){
$('.allEmployees').attr(“选中”,为真);
}否则{
$(“.allEmployees”).attr('checked',false);
if($rootScope.fromMovingPage!=2&&$rootScope.fromMovingPage!=3){
//由于我们现在已取消选中所有员工,因此我们需要进行匹配,并选择大小为0的员工列表
$scope.matching和selectedemployeeslist.length=0;
}
}
}
}

在onclick事件中,如果您传递一个事件变量

function(e) {

}
您可以键入:

function(e) {
    e.preventDefault();
}

我相信这就是您的要求。

请分享您的代码,您到目前为止都做了些什么。