angularjs中的复选框checkbox

来源:互联网 发布:sql server exists用法 编辑:程序博客网 时间:2024/05/21 00:55
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="http://cdn.static.runoob.com/libs/angular.js/1.4.6/angular.min.js"></script>
</head>
<body ng-app="">
    <p>My cars:</p>
    <input type="checkbox" ng-model="all"> Check all<br><br>
    <input type="checkbox" ng-checked="all">Volvo<br>
    <input type="checkbox" ng-checked="all">Ford<br>
    <input type="checkbox" ng-checked="all">Mercedes
    <p>点击 "Check all" 选择所有的车。</p>
</body>

</html>


当点击Check all按钮时,ng-model="all"中绑定的all的值变为为true,相应的ng-checked=“all中的all值也都变为true,即其他按钮都被选中。

另外一例子:

html代码:

<div class="form-control">

<input type="checkbox" ng-model="aaa"  value="某一值">宝马</input>

<input type="checkbox" ng-model="bbb"  value="另外一值">奥利奥</input>

</div>

//checkbox 选中时返回值只为true或 false,如果选中“”“宝马”则&scope.aaa=true。 其中不管上述“宝马”或“奥利奥”两个复选框选中没选中,其value值永远为“某一值”或“另外一值”

div class="form-control">

<input type="radio" ng-model="aaa"  value="某一值">宝马</input>

<input type="radio" ng-model="aaa"  value="另外一值">奥利奥</input>

</div>

//radio选中时返回的值为其所对应的属性value所返回的值,如果选中“宝马”则在$scope.aaa的值为“某一值”。

控制器中的代码为:

$scope.aaa="某一值"


0 1
原创粉丝点击