Javascript 如果变量为true,如何强制进行下拉选择?
我有一个角js下拉列表。我希望如果我的变量,例如“x”的值为true,则必须从下拉列表中选择一个值,如果值为false,则可以允许它保存该值,而无需从下拉列表中选择任何内容。这是我的下拉列表:Javascript 如果变量为true,如何强制进行下拉选择?,javascript,angularjs,dropdown,Javascript,Angularjs,Dropdown,我有一个角js下拉列表。我希望如果我的变量,例如“x”的值为true,则必须从下拉列表中选择一个值,如果值为false,则可以允许它保存该值,而无需从下拉列表中选择任何内容。这是我的下拉列表: <select class="form-control dropdownheight" ng-model="search.hardware" ng-change="search()" > <option value="" selected>S
<select class="form-control dropdownheight"
ng-model="search.hardware"
ng-change="search()" >
<option value="" selected>Select Hardware</option>
<option ng-repeat="box in boxes" value="{{box.name}}">{{box.name}}</option>
</select>
选择硬件
{{box.name}
使用:
选择硬件
{{box.name}
请参见您可以为此使用所需的ng
<form name="form">
<select ng-model="hardware" class="form-control dropdownheight" ng-change="search()" >
<option value="" selected>Select Hardware</option>
<option ng-repeat="box in boxes" value="{{box.name}}">{{box.name}}</option>
</select>
<label for="input">This input must be filled if `required` is true: </label>
<input type="text" id="input" name="input" ng-required="isRequired" /><br>
<hr>
<code>{{form.input.$error}}</code><br>
isRequired = <code>{{isRequired}}</code>
<input type="submit" value="Save" ng-disabled="isRequired"/>
</form>
我已经为它创建了plunkr:
谢谢:)我修改了它并创建了一个函数来获得所需的功能。谢谢你的帮助
<form name="form">
<select ng-model="hardware" class="form-control dropdownheight" ng-change="search()" >
<option value="" selected>Select Hardware</option>
<option ng-repeat="box in boxes" value="{{box.name}}">{{box.name}}</option>
</select>
<label for="input">This input must be filled if `required` is true: </label>
<input type="text" id="input" name="input" ng-required="isRequired" /><br>
<hr>
<code>{{form.input.$error}}</code><br>
isRequired = <code>{{isRequired}}</code>
<input type="submit" value="Save" ng-disabled="isRequired"/>
</form>