神秘(对我来说)“对象不支持此属性或方法”错误 - JavaScript HTML 推出

发布于 2024-11-04 16:48:05 字数 798 浏览 0 评论 0原文

我从第 4 行的 Char 1 收到上述错误...不知道是什么抛出了它?我确信这是我看不到的简单事情......

out = out + "<b>Select Box Information</b><br><br> The name of the select box is: skeletor. A play on the word selector.<br>"
out = out + "The options for the select box are, Default Value, Option 2, Option 3, Option 4 and Option 5.<br>"
out = out + "The values for each option, from top to bottom, are: " + lucy.skeletor.option(0) + ", "
out = out + lucy.skeletor.option(1) + ", " + lucy.skeletor.option(2) + ", " + lucy.skeletor.option(3)
out = out + ", " + lucy.skeletor.option(4) + ".<br><br>"
out = out + "The index of the first option in the select box is: 0. The location of the user-selected option is: " + lucy.skeletor.value + ".<br><br>"

I'm getting the error above from Char 1 of the 4th line... No clue what's throwing it? I'm sure its something simple that I don't see...

out = out + "<b>Select Box Information</b><br><br> The name of the select box is: skeletor. A play on the word selector.<br>"
out = out + "The options for the select box are, Default Value, Option 2, Option 3, Option 4 and Option 5.<br>"
out = out + "The values for each option, from top to bottom, are: " + lucy.skeletor.option(0) + ", "
out = out + lucy.skeletor.option(1) + ", " + lucy.skeletor.option(2) + ", " + lucy.skeletor.option(3)
out = out + ", " + lucy.skeletor.option(4) + ".<br><br>"
out = out + "The index of the first option in the select box is: 0. The location of the user-selected option is: " + lucy.skeletor.value + ".<br><br>"

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

蒗幽 2024-11-11 16:48:05

我认为 lucy.skeletor.option(1) 将是这里的问题。如果lucy.skeletor是一个真正的select元素,它包含一个options数组。该数组可以像这样引用:lucy.skeletor.options[n]

此外,如果您连接,您可以这样做:

out += somestring+someotherstring+morestrings ... etc

I'd think lucy.skeletor.option(1) will be the problem here. If lucy.skeletor is a genuine select element, it contains an options array. That array can be referenced like: lucy.skeletor.options[n]

furthermore, if you concatenate, you could do:

out += somestring+someotherstring+morestrings ... etc
空城缀染半城烟沙 2024-11-11 16:48:05

out = out + ... 可以,只是没有必要。
您的问题是使用 .option(1) 访问不存在的集合

如果 skeletor 是 a 那么较新浏览器的正确语法是

lucy.options[1].value 或 .text

这就是我认为您的意思

var out = "";
out += "<b>Select Box Information</b><br><br> The name of the select box is: skeletor. A play on the word selector.<br>"
out += "The options for the select box are, Default Value, Option 2, Option 3, Option 4 and Option 5.<br>"
out += "The values for each option, from top to bottom, are: "
var opts=[]; 
for (var i=0;i<lucy.skeletor.options.length;i++) opts.push(lucy.skeletor.options[0].text); 
out += opts.join(", ");
out += ".<br><br>"
out += "The index of the first option in the select box is: 0. The location of the user-selected option is: " + lucy.skeletor.value + ".<br><br>"

out = out + ... is ok, just not necessary.
Your problem is using .option(1) which is accessessing a non-existing collection

If skeletor is a then the correct syntax for newer browsers is

lucy.options[1].value or .text

Here is what I think you meant

var out = "";
out += "<b>Select Box Information</b><br><br> The name of the select box is: skeletor. A play on the word selector.<br>"
out += "The options for the select box are, Default Value, Option 2, Option 3, Option 4 and Option 5.<br>"
out += "The values for each option, from top to bottom, are: "
var opts=[]; 
for (var i=0;i<lucy.skeletor.options.length;i++) opts.push(lucy.skeletor.options[0].text); 
out += opts.join(", ");
out += ".<br><br>"
out += "The index of the first option in the select box is: 0. The location of the user-selected option is: " + lucy.skeletor.value + ".<br><br>"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文