如何在jquery中重置下拉列表,以便不选择任何内容?
我在模态中有这个下拉列表如何在jquery中重置下拉列表,以便不选择任何内容?,jquery,Jquery,我在模态中有这个下拉列表 <div class="control-group"> <label class="control-label" for="selectInsert01">Country Name:</label> <div class="controls"> <select id="selectInsert01" class="input-xlarge with-search" data-bind=
<div class="control-group">
<label class="control-label" for="selectInsert01">Country Name:</label>
<div class="controls">
<select id="selectInsert01" class="input-xlarge with-search" data-bind="foreach: citiesModel.countriesList">
<option data-bind="text: Name, value: CountryID"></option>
</select>
</div>
</div>
国家名称:
每次我选择某个内容并退出模式,然后再次打开它时,下拉列表中的选定值仍然处于选中状态。如何重置值,以便在模式关闭时退出模式时不选择任何内容
$("#selectInsert01 option:eq(0)").prop("selected", true); //set option of index 0 to selected
您可以根据需要重置下拉列表
$("#selectInsert01 option:first").attr("selected", true);
但它只会更改下拉列表的选定值,而不会更改用户可见的标签,因此您也必须更改它。为此,您可以:
$(".control-label").text($("#selectInsert01 option:first").val());
这对我有用。希望能有帮助
$("#selectInsert01 option:selected").removeAttr("selected");
如果您在下拉列表中使用了引导类选择器选择器:
$('.selectpicker').selectpicker('val', '-1');
您也可以参考此链接:如果您有占位符,您可以执行以下操作:
$("#selectBox").val($("#selectBox option:first").val());
如果占位符不包含值,则更简单:
$("#selectBox").val(0);
向我们展示您的模式脚本代码。