HTML/选择单选按钮不';行不通
我想在默认情况下选择一个单选按钮。据我所知,我应该添加checked属性:HTML/选择单选按钮不';行不通,html,angularjs,radio-button,Html,Angularjs,Radio Button,我想在默认情况下选择一个单选按钮。据我所知,我应该添加checked属性: <table> <tr> <b> Storage </b> </tr> <tr> <td> <div
<table>
<tr>
<b> Storage </b>
</tr>
<tr>
<td>
<div class="form-group">
<input type="radio" name="store" value="local" ng-model="store" checked="checked" /> Local
</div>
</td>
<td>
<div class="form-group">
<input type="radio" name="store" value="second" ng-model="store" /> Second (Amazon)
</div>
</td>
<td>
<div class="form-group">
<input type="radio" name="store" value="cloud" ng-model="store" /> Cloud
</div>
</td>
</tr>
</table>
存储
地方的
第二(亚马逊)
云彩
但默认情况下不选中“本地”(不选中任何内容)。为什么?
提前感谢不要写checked=“checked”
执行以下操作:
<input type="radio" name="store" value="local" ng-model="store" checked /> Local
本地
不要写checked=“checked”
执行以下操作:
<input type="radio" name="store" value="local" ng-model="store" checked /> Local
本地
由于您使用的是angular,并且您将单选按钮绑定到模型,因此angular会根据模型对其进行状态处理
因此,您应该将模型的store属性设置为radio的值,而不是手动尝试设置radio的选中状态
$scope.store = "local";
由于您使用的是angular,并且您将单选按钮绑定到模型,因此它的状态处理由angular根据模型完成 因此,您应该将模型的store属性设置为radio的值,而不是手动尝试设置radio的选中状态
$scope.store = "local";
使用选中的属性
<input type="radio" name="store" value="local" ng-model="store" checked /> Local
本地
更新
您应该使用Angular附带的ngChecked指令。使用选中属性
<input type="radio" name="store" value="local" ng-model="store" checked /> Local
本地
更新
您应该使用Angular附带的ngChecked指令。刚刚将代码粘贴到JSFIDLE中。它在那里工作。。。看起来您的角度绑定正在破坏它,只是将代码粘贴到JSFIDLE中。它在那里工作。。。看来你的角绑定正在破坏它