简体   繁体   English

默认选择的选项用于在IE中使用javascript进行html选择

[英]default selected option for html select using javascript in IE

Hello I have a select element and I am trying to set a default option for that select element. 您好我有一个select元素,我正在尝试为该select元素设置一个默认选项。 But my code isn't working in IE. 但是我的代码在IE中不起作用。 Is there any way around for this?? 这有什么办法?

if(objOption.value == selectedoption)
{ alert(objOption.value);
objOption.defaultSelected = true;
}

I am able to retreive the option, and its value, but am unable to set the defaultSelected value. 我能够检索该选项及其值,但无法设置defaultSelected值。

As stated in the documentation , the defaultSelected property is only used if you click an <input type="reset" /> . 文档中所述,仅当您单击<input type="reset" />时才使用defaultSelected属性。

To immediately select the <option> , you should also set the selected property to true . 要立即选择<option> ,还应将selected属性设置为true

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

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