加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

AngularJS ng-checked指令

发布时间:2020-12-17 09:55:54 所属栏目:安全 来源:网络整理
导读:定义和用法 ng-checked 指令用于设置复选框(checkbox)或单选按钮(radio)的 checked 属性。 如果 ng-checked 属性返回 true,复选框(checkbox)或单选按钮(radio)将会被选中。 语法 input type= "checkbox|radio" ng-checked= " expression " /input type 为 c

定义和用法

ng-checked指令用于设置复选框(checkbox)或单选按钮(radio)的 checked 属性。

如果ng-checked属性返回 true,复选框(checkbox)或单选按钮(radio)将会被选中。

语法

< input type= "checkbox|radio" ng-checked= "expression" > /input >

type 为 checkbox 或 radio 的 <input> 元素支持。


参数值

描述
expression 如果返回 true,将会选中元素选项。
简单实例:

JS代码

var app = angular.module('myApp',[]);
app.controller('validateCtrl',function ($scope) {
    $scope.sex = true;
    $scope.agree = true;
    $scope.clickOne = function () {
        $scope.sex = !$scope.sex;
        $scope.agree = !$scope.agree;
    }
});

HTMl代码

    <h3>Radio 控件测试</h3>
    <p>
        <label>
            <input type="radio" value="男" name="sex" ng-model="value1" ng-checked="sex" />
            男
        </label>
        <label>
            <input type="radio" value="女" name="sex" ng-model="value1" ng-checked="!sex" />
            女
        </label>
        <button class="btn btn-default" ng-click="clickOne();">修改</button>
    </p>
    <h3>checked 控件测试</h3>
    <p>
        <div class="checkbox">
            <label>
                <input name="agree" type="checkbox" value="同意" ng-model="value2" ng-checked="agree" />
                同意协议
            </label>
        </div>
        <div class="checkbox">
            <label>
                <input name="agree" type="checkbox" value="同意2" ng-model="value2" ng-checked="agree" />
                同意协议2
            </label>
        </div>
    </p>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读