2016-01-21 140 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