【问题标题】:Mysterious (to me) "object doesn't support this propery or method error - JavaScript HTML rollout神秘(对我而言)“对象不支持此属性或方法错误 - JavaScript HTML 推出
【发布时间】:2011-05-02 08:48:15
【问题描述】:

我从第 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>"

【问题讨论】:

  • 为了帮助您,我们必须知道lucylucy.skeletorlucy.skeletor.option 是什么。该错误表明您尝试访问的两个属性之一不存在。
  • 我们需要您提供更多信息。您还使用什么类型的插件或框架?

标签: javascript html rollout


【解决方案1】:

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

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

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

【讨论】:

  • 我的上帝,你对 += 的看法是正确的,我一直在 VBScript 和 JavaScript 之间切换类,它让事情陷入困境......我会尝试你建议的修复快速通知您。
  • 在这种情况下,使用[string, string, ...].join('') 可能会更好。
  • 一切都清除了 IE 调试器,现在只是没有推出 HTML :-\ 我会搞砸的。谢谢 Kooilnc
【解决方案2】:

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>"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-14
    • 1970-01-01
    相关资源
    最近更新 更多