问题描述
我正在定制<选择>
的。但我被困一个问题后面。快速的console.log(选项);
显示阵列的结果是:
I'm working on customizing <select>
's. But I got stuck behind a problem. A quick console.log(options);
shows the array's result:
[不确定的,不确定的,赛琳娜·戈麦斯,蜜拉库妮丝,不确定的,不确定的,不确定的,不确定的,不确定的,不确定的,不确定的,麦莉·赛勒斯]
此外,当我做警报(options.length);
,结果是12.当现实中有4个选项中选择。
Also when I do alert(options.length);
the result is 12. When in reality there are 4 options in the select..
code产生的数组:
Code that produces the array:
var options = new Array;
$(this).children('option').each(function () {
if ($(this).val()) {
options[$(this).val()] = $(this).text();
}
});
console.log(options);
我不知道是什么问题。我添加了如果($(本).VAL())
,可以肯定的,即无静电的变数组,但仍。
I have no clue what is the issue.. I added the if ($(this).val())
, to be sure, that no static gets in the array, but still.
注意:然而,当我在Firebug打开阵列起来,那只能说明正确的条目
Note: However, when I open the array up in firebug, it only shows the correct entries.
推荐答案
$(本).VAL()
不能为0,1,2,3,那么,而是2,3,11(其中是4?)
$(this).val()
must not be 0, 1, 2, 3 then, but rather 2, 3, 11 (where is the 4th?)
使用 options.push($(本)的.text());
代替或将其作为一个对象,以避免丢失索引自动生成
Use options.push($(this).text());
instead or use it as an object to avoid auto generation of missing indexes.
此外, $(本).VAL()
将评估为假
如果是空的,
或 0
,是第四届一个部分可能是?
Also, $(this).val()
will evaluate to false
if it is empty ""
or 0
, is that the 4th one perhaps?
这篇关于Firebug是一个数组中显示大量不确定项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!