AngularJS ng-selected
指令
AngularJS 實例
獲取選中的選項:
點擊複選框選擇 BMW 選項:
<input type="checkbox" ng-model="mySel">
<p>我喜歡的車:</p>
<select>
<option>Volvo</option>
<option ng-selected="mySel">BMW</option>
<option>Ford</option>
</select>
<input type="checkbox" ng-model="mySel">
<p>我喜歡的車:</p>
<select>
<option>Volvo</option>
<option ng-selected="mySel">BMW</option>
<option>Ford</option>
</select>
定義和用法
ng-selected 指令用於設置 <select> 列表中的 <option> 元素的 selected 屬性。
ng-selected
屬性的運算式返回 true 則選項被選中。
語法
<option ng-selected="expression"></option>
<option> 元素支持該指令。
參數值
值 | 描述 |
---|---|
expression | 如果運算式為 true 則選項被選中 |