【问题标题】:How to make a radio button checked by default如何使单选按钮默认选中
【发布时间】:2015-09-01 04:32:23
【问题描述】:

我有 3 个单选按钮 - 全部、通过、失败。我希望在 ng-model 中默认检查所有单选按钮的值。

我怎样才能做到这一点?

如果我使用的是 ng-checked = "true",它会检查但我没有得到我模型变量中 All 的选定收音机的值。

如果我使用checked="checked" 或检查这也没有给我模型中的价值 变量。

input type="radio" value="all" ng-checked="true" ng-model="model" 

当我在控制器中访问 $scope.model 时加载页面时,我想要所有的值。

有任何帮助

【问题讨论】:

标签: javascript html angularjs


【解决方案1】:
<div ng-app>
<div ng-init="x=1" />
<input type="radio" ng-model="x" value="1">1 <br/>
<input type="radio" ng-model="x" value="2">2 <br/>
<div>{{x}}</div>
</div>

【讨论】:

    【解决方案2】:

    Demo

    HTML

    <section ng-app="app">
         <h2 ng-controller="controller">
                    <input type="radio"  value="1" ng-model="ChkBox"/> Checkbox 1
                    <input type="radio" value="2" ng-model="ChkBox"/> Checkbox 2
                </h2>
    </section>
    

    JS

    var app = angular.module('app', []);
    function controller($scope) {
        $scope.ChkBox = '1';   
    }
    

    【讨论】:

      猜你喜欢
      • 2018-12-26
      • 1970-01-01
      • 2017-10-02
      • 1970-01-01
      • 2021-01-06
      • 1970-01-01
      • 2014-03-08
      • 2018-04-21
      • 2013-03-01
      相关资源
      最近更新 更多