这些情况因具有单个选项的选择框和具有多个选项的选择框而异.
对于具有单个选项的选择框:
<select id='selectbox'>
Run Code Online (Sandbox Code Playgroud)
jQuery代码:
$('#button').click(function() {
$('#selectbox').attr('selectedIndex', '-1');
});
Run Code Online (Sandbox Code Playgroud)
注意:您需要此变体才能使其在Internet Explorer中正常工作.以下示例也适用于Internet Explorer中的单个选项文本框.
对于具有多个选项的选择框:
<select id='selectbox' multiple='multiple'>
Run Code Online (Sandbox Code Playgroud)
jQuery代码:
$('#button').click(function() {
$('#selectbox option').attr('selected', '');
});
Run Code Online (Sandbox Code Playgroud)