简体   繁体   English

如何在jQuery中清除列表框中的值

[英]how to clear values in listbox in jquery

I want to clear the values from list box and I used this code to clear 我想清除列表框中的值,并使用此代码清除

$("#transfernumber").empty();

It is not working any other options available. 它无法使用任何其他可用选项。

<label>Send Coupon No.</label>
<span class="divider" style="width:auto">:</span>

<select value="" name="transfernumber" id="transfernumber">
   <option data-amount="data-amount">Select Coupon Number</option> 
</select>

after writing this code only it works 编写此代码后,它才有效

$("#transfernumber").multiselect('refresh');

your jquery 你的jQuery

$('#transfernumber > option').remove();

Demo 演示版

尝试这个:

$("#transfernumber option").remove();

You can also use: 您还可以使用:

$('#transfernumber')[0].options.length = 0;

or 要么

$('#transfernumber').find('option').remove();

只需执行以下操作,它将删除选择框中的所有选项

$("#transfernumber").html("");

Try this, 尝试这个,

$("#transfernumber").val('');// to clear the value
// to select the first option, as usual it may be "Select list"
$("#transfernumber option:first").prop('selected',true);

And if you want to remove all options then use html() 如果要删除所有options使用html()

$("#transfernumber").html('');// to remove all options

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM