I don't want to remove the options, just clear the selected value.
I tried the following:
$("#myid").val("")
and that does not seem to work.
你可以使用prop
方法。
$("#myid option:selected").prop("selected", false)
只有当你有一个空值的选项时,这才有效:
<option value=""></option>
You can try this
HTML CODE
<select id="myid">
<option value="">Select None</option>
<option value="0" id="item1">Item 1</option>
<option value="1" id="item1">Item 2</option>
<option value="2" id="item2">Item 3</option>
<option value="3" id="item3">Item 4</option>
</select>
JS CODE
$(document).ready(function(){
$('#myid').change(function(){
var getVal= $('#myid').select().attr('value');
$('option[id=item'+getVal+']').attr('value','');
});
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.