如何使用 jQuery 清除按钮单击事件上的下拉列表值? [英] How do I clear the dropdownlist values on button click event using jQuery?
本文介绍了如何使用 jQuery 清除按钮单击事件上的下拉列表值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用 jQuery 清除按钮单击事件的下拉列表值?
How do I clear the dropdownlist values on button click event using jQuery?
推荐答案
Russ Cam 给出的第一个解决方案的更短的替代方案是:
A shorter alternative to the first solution given by Russ Cam would be:
$('#mySelect').val('');
这假设您要保留列表,但不要选择任何选项.
This assumes you want to retain the list, but make it so that no option is selected.
如果您希望选择特定的默认值,只需传递该值而不是空字符串.
If you wish to select a particular default value, just pass that value instead of an empty string.
$('#mySelect').val('someDefaultValue');
或者通过选项的索引来做,你可以这样做:
or to do it by the index of the option, you could do:
$('#mySelect option:eq(0)').attr('selected','selected'); // Select first option
这篇关于如何使用 jQuery 清除按钮单击事件上的下拉列表值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文