Javascript 在 IE8 中出现错误
我有一个名为 onchange 的 js 函数。 它适用于 FF、IE6 和 7 以及 Safari。 然而,在 IE8 中,该函数在下一行中断。
document.getElementById("shipModeId_1").options[document.getElementById("shipModeId_1").options.length]
= Option(ship_modeId,selcted);
它说对象不支持此属性或方法。 知道为什么会发生这种情况吗?
谢谢,
萨雷戈
I have a js function which is called onchange of a drop-down.
It works in FF, IE6 and 7 and Safari.
In IE8 however the function breaks at the following line.
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.
Any idea why this is happening?
Thanks,
Sarego
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您错过了
new
运算符。此外,您可能希望为text
和value
参数传递相同的值,并在其后添加selected
。Option
构造函数的两个参数形式采用text
和value
,而不是selected
。You missed the
new
operator. Also you probably want to pass in the same value for thetext
and thevalue
arguments, withselected
following that. The two-argument form of theOption
constructor takestext
andvalue
, notselected
.如果这是用于
您在生成新选项时还错过了“新”。
If this is for a
<select>
, I don't think you need "options".You also missed "new" in generating the new option.
用这个,
Use this,