我有MultipleSeletion Dropdown我想取消选择下拉列表的值,不知道如何做到这一点

时间:2016-06-28 11:36:47

标签: javascript asp.net dropdown

现在我使用此代码取消选择下拉列表的选定值,但它不起作用

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;
}

2 个答案:

答案 0 :(得分:0)

'=='是比较操作,您需要使用'='

&#13;
&#13;
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;
&#13;
&#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("");