2016-01-21 142 views
0

我想在默认情况下选择一个单选按钮。据我所知,我应该添加检查属性:HTML/Select单选按钮不起作用

<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> 

但是本地不默认选中(没有检查)。为什么?提前

感谢

回答

2

由于您使用的角度和你绑定你的单选按钮,你的模型,它的状态处理由角基于该模型进行。

因此,您应该将模型的商店属性设置为无线电的值,而不是手动尝试设置收音机的选中状态。

$scope.store = "local"; 
1

不要写checked="checked"做到这一点:

<input type="radio" name="store" value="local" ng-model="store" checked /> Local 
+0

我已经试过了。相同... – MiddleWare

+0

https://jsfiddle.net/4xkmd2oc/1/只是在jsfiddle中粘贴了你的代码。它正在工作......看起来你的角色绑定正在破坏它 – FKutsche