Javascript 在 IE8 中出现错误

发布于 2024-10-01 01:23:40 字数 306 浏览 0 评论 0原文

我有一个名为 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

梦过后 2024-10-08 01:23:40

您错过了 new 运算符。此外,您可能希望为 textvalue 参数传递相同的值,并在其后添加 selectedOption 构造函数的两个参数形式采用 textvalue,而不是 selected

new Option(ship_modeId, ship_modeId, selected)

You missed the new operator. Also you probably want to pass in the same value for the text and the value arguments, with selected following that. The two-argument form of the Option constructor takes text and value, not selected.

new Option(ship_modeId, ship_modeId, selected)
浅笑依然 2024-10-08 01:23:40

如果这是用于

document.getElementById("shipModeId_1")[document.getElementById("shipModeId_1").length]  = new Option(ship_modeId,selcted); 

您在生成新选项时还错过了“新”。

If this is for a <select>, I don't think you need "options".

document.getElementById("shipModeId_1")[document.getElementById("shipModeId_1").length]  = new Option(ship_modeId,selcted); 

You also missed "new" in generating the new option.

柠檬色的秋千 2024-10-08 01:23:40

用这个,

var drpDown = document.getElementById("shipModeId_1");
drpDown.options[drpDown.options.length] = new Option(ship_modeId,selcted);

Use this,

var drpDown = document.getElementById("shipModeId_1");
drpDown.options[drpDown.options.length] = new Option(ship_modeId,selcted);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文