如果在下拉列表中未选择任何内容,请禁用按钮

时间:2017-06-02 08:51:26

标签: angularjs button angularjs-ng-disabled

如果在下拉列表中未选择任何内容,则应取消该按钮。我怎样才能做到这一点?

<select size='1' id="action" ng-model="ak.action">
    <option value='1'>RED</option>
    <option value='2'>BLUE</option>
</select>

<div>
    <button type="button" ng-Click="ak.save()" >SAVE</button>
</div>

1 个答案:

答案 0 :(得分:1)

尝试使用按钮上的ng-disabled="!ak.action || ak.action.length == 0"。 虽然select将始终包含您选择的项目......

<select size='1' id="action" ng-model="ak.action">
        <option value='1'>RED</option>
        <option value='2'>BLUE</option>
</select>

<div>
    <button ng-disabled="!ak.action || ak.action.length == 0" type="button" ng-click="ak.save()" >SAVE</button>
</div>