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 則選項被選中 |