在angularjs中动态添加/删除checked属性到checkbox复选框
16lz
2021-01-22
How can i simply add and remove checked attribute to check-box using angularjs. I've find solution from this question,but it requires Jquery
如何使用angularjs简单地添加和删除选中的属性到复选框。我从这个问题找到解决方案,但它需要Jquery
Is any other way to do this without using Jquery?
没有使用Jquery,还有其他方法吗?
Here is what i am tried
这是我的尝试
<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="";
}
}
But the removing wont work
但删除不会工作
4 个解决方案
#1
6
This is Angularjs recommended way of check and un check checkbox
这是Angularjs推荐的check and un check复选框
HTML : <input type="checkbox" ng-model="checkVal" ng-true-value="true" ng-false-value="false">
HTML:
Also works
<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;
}
}
更多相关文章
- HTML5 数据集属性dataset
- 浏览器如何处理HTML元素上的无效/未指定的属性?
- Javascript学习:案例7--对象属性和方法的遍历、删除、添加.html
- javascript 构造函数中的属性与原型上属性优先级的比较
- 在jQuery中使用css transform属性
- javascript的offset、client、scroll使用方法,相关属性解释原理
- 如何将javascript set style属性返回到CSS默认值
- 对象的属性也要加引号吗
- javascript中的属性类型