我如何使用 angularjs 简单地向复选框添加和删除选中的属性。 我从 this 找到了解决方案问题,但它需要 Jquery
有没有其他方法可以不使用 Jquery 来做到这一点?
这是我尝试过的
<input type="checkbox" id="test" class="switch__input" checked="{{checkVal}}">
<input type="button" ng-click="test()" value="test">
JS
module.controller('settingsCtrl',function($scope){
//for adding
$scope.checkVal="checked";
//for removing checkbox
$scope.test=function(){
$scope.CheckVal="";
}
}
但是删除不会起作用
最佳答案
这是 Angularjs推荐的勾选和取消勾选方式
HTML :
<input type="checkbox" ng-model="checkVal" ng-true-value="true" ng-false-value="false">
也有效
<input type="checkbox" ng-checked="checkVal">
JS :
module.controller('settingsCtrl',function($scope){
//for adding
$scope.checkVal=true;
//for removing checkbox
$scope.test=function(){
$scope.checkVal=false;
}
}
关于javascript - 在angularjs中动态添加/删除复选框的选中属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31980694/