现在我使用此代码取消选择下拉列表的选定值,但它不起作用
var Diag = document.getElementById('<%=selDiag.ClientID%>');
var diag1 = "";
var diag2 = "";
var diag3 = "";
var diag4 = "";
var options = Diag.getElementsByTagName('option');
for (var i = 0, len = options.length; i < len; i++) {
options[i].selected == false;
}
答案 0 :(得分:0)
'=='
是比较操作,您需要使用'='
var Diag = document.getElementById('tst');
var options = Diag.getElementsByTagName('option');
for (var i = 0, len = options.length; i < len; i++) {
options[i].selected = false;
}
&#13;
<select id="tst" multiple>
<option value="volvo" selected>Volvo</option>
<option value="saab">Saab</option>
<option value="vw">VW</option>
<option value="audi" selected>Audi</option>
</select>
&#13;
答案 1 :(得分:0)
为您想要的项目设置值=“”或“0”作为默认选定项目.. 这是一个例子..
<select id="To_Year" class="form-control" style="color: black; height: 36px; margin: 4px; text-align: center;">
<%Response.Write("<option value=''>To Year</option>");
for (Int32 cnt = 2000; cnt <= (DateTime.Now.Year) + 5; cnt++)
{
Response.Write("<option value='" + cnt + "'>" + cnt + "</option>");
}
%>
</select>
简单地在你的脚本中调用它们如下......
$("#To_Year").val("");
OR
document.getElementById('<%=To_Year.ClientID%>').val("");