【发布时间】:2015-11-01 19:36:21
【问题描述】:
这是控制台的一些输出,说明了我的问题
var a=document.createElement("select"); <ENTER>
undefined
a.appendChild(document.createElement("option")); <ENTER>
<option></option>
a
<select>…</select>
a.options
[<option></option>]
a.options[0];
<option></option>
到目前为止,一切都很好。 但是现在
我输入 a.options. 并输入 forEach 但我注意到 forEach 没有被列出。
a.options.forEach(function() {});
VM1048:2 Uncaught TypeError: a.options.forEach is not a function
at <anonymous>:2:11
at Object.InjectedScript._evaluateOn (<anonymous>:905:140)
at Object.InjectedScript._evaluateAndWrap (<anonymous>:838:34)
at Object.InjectedScript.evaluate (<anonymous>:694:21)
然而 a.options 看起来像一个数组
而且 forEach 绝对适用于数组,没有错误。
a=[1,2];
[1, 2]
typeof a
"object"
a.forEach(function(){});
undefined
我猜选择框的选项可能不是数组.. 那么它们是什么?
我听说过'arguments' 伪数组。我想也许选择框的'options' 是这样的? / 一些与数组语法相似的对象?
【问题讨论】:
标签: javascript