admin管理员组文章数量:1335552
Well, I have the really super simple stuff in jsfiddle. I am experimenting to make sure I can do it right in jquery first before I have to dynamically generate the jquery in C#. Basically the jQuery is suppose to populate an html based on values in an array.
You can view the fiddle here /
This is what I have so far. But its not working.
var makes = new array();
makes[0] = 'HOONDA';
makes[1] = 'MEETSUBITCHE';
makes[2]= 'NEWSMOBILE';
makes[3]= 'FJORD';
for(var i=0; i<makes.length; i++)
{
$('#2').append('<option value=1>'+makes[i]+'</option>');
}
And in the HTML:
<select id="2" multiple="multiple">
<option> 10</option>
</select>
Well, I have the really super simple stuff in jsfiddle. I am experimenting to make sure I can do it right in jquery first before I have to dynamically generate the jquery in C#. Basically the jQuery is suppose to populate an html based on values in an array.
You can view the fiddle here http://jsfiddle/KwVty/
This is what I have so far. But its not working.
var makes = new array();
makes[0] = 'HOONDA';
makes[1] = 'MEETSUBITCHE';
makes[2]= 'NEWSMOBILE';
makes[3]= 'FJORD';
for(var i=0; i<makes.length; i++)
{
$('#2').append('<option value=1>'+makes[i]+'</option>');
}
And in the HTML:
<select id="2" multiple="multiple">
<option> 10</option>
</select>
Share
Improve this question
asked Jul 12, 2013 at 17:28
Alexander Ryan BaggettAlexander Ryan Baggett
2,3974 gold badges36 silver badges67 bronze badges
5
-
1
The option value is 1 in all cases. Replace
/1/"+i+"/
– Lee Meador Commented Jul 12, 2013 at 17:31 -
2
Array
has an uppercaseA
, not a lowercasea
. – gen_Eric Commented Jul 12, 2013 at 17:32 - 30 seconds too late you are :-P – Naftali Commented Jul 12, 2013 at 17:33
-
2
Some advice, check your developer tools / console. You would've seen an error about
array
not being defined. – gen_Eric Commented Jul 12, 2013 at 17:33 - see my answer here: stackoverflow./questions/9995017/… – Walter Stabosz Commented Jul 12, 2013 at 17:40
2 Answers
Reset to default 8There is no such thing as array
natively in javascript.
I think you meant to use new Array()
(note the uppercase A
) or []
array
(wrong) is declared as Array
var makes = new Array();
Working Demo http://jsfiddle/KwVty/1/
本文标签: javascriptAdd select options using jquery and arraysStack Overflow
版权声明:本文标题:javascript - Add select options using jquery and arrays - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742396200a2466971.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论