[英]Javascript gives error in IE8
I have a js function which is called onchange of a drop-down. 我有一个js函数,它被称为on drop of down-down。 It works in FF, IE6 and 7 and Safari.
它适用于FF,IE6和7以及Safari。 In IE8 however the function breaks at the following line.
但是在IE8中,该函数在以下行中断。
document.getElementById("shipModeId_1").options[document.getElementById("shipModeId_1").options.length]
= Option(ship_modeId,selcted);
It says Object doesn't support this property or method. 它说Object不支持这个属性或方法。 Any idea why this is happening?
知道为什么会这样吗?
Thanks, 谢谢,
Sarego Sarego
You missed the new
operator. 你错过了
new
运营商。 Also you probably want to pass in the same value for the text
and the value
arguments, with selected
following that. 此外,您可能希望为
text
和value
参数传递相同的值,并在此之后selected
。 The two-argument form of the Option
constructor takes text
and value
, not selected
. Option
构造函数的两个参数形式采用text
和value
,而不是selected
。
new Option(ship_modeId, ship_modeId, selected)
If this is for a <select>
, I don't think you need "options". 如果这是一个
<select>
,我认为你不需要“选项”。
document.getElementById("shipModeId_1")[document.getElementById("shipModeId_1").length] = new Option(ship_modeId,selcted);
You also missed "new" in generating the new option. 您在生成新选项时也错过了“新”。
Use this, 用这个,
var drpDown = document.getElementById("shipModeId_1");
drpDown.options[drpDown.options.length] = new Option(ship_modeId,selcted);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.