admin 管理员组文章数量: 1086019
Hey guys i bet this is an easy question but cant seem to find any help online, i have a select List box and i would like to get each list text and split them up into an array of how big the list box is without the user selecting the value. Right now my list box makes random values so the list can go up to 100
Example
<select id="selectBox">
<option value="1">Select One</option> <--- I want just the text to input into array
<option vaue="2">Select Two</option>
</select>
Hey guys i bet this is an easy question but cant seem to find any help online, i have a select List box and i would like to get each list text and split them up into an array of how big the list box is without the user selecting the value. Right now my list box makes random values so the list can go up to 100
Example
<select id="selectBox">
<option value="1">Select One</option> <--- I want just the text to input into array
<option vaue="2">Select Two</option>
</select>
Share
Improve this question
edited May 20, 2010 at 19:04
Silent
asked May 20, 2010 at 18:50
SilentSilent
6811 gold badge16 silver badges34 bronze badges
1
- Could you give an example with some code? I'm not sure what you mean when you say "list text" and "how big the list box is". Split them up by what? – Kerry Jones Commented May 20, 2010 at 18:54
2 Answers
Reset to default 4There is already that functionality in the HTML Dom
Here is a referencing link for the HTML Dom SelectElement Options http://www.w3schools./jsref/coll_select_options.asp
var myoptions = $("#mySelectElementid")[0].options;
from here you can do the following
myoptions.length;
myoptions[0].value;
myoptions[0].text;
Use the DOM to get at them:
var options = document.getElementById("selectBox");
var optArray = [];
for (var i = 0; i < options.length; i++) {
optArray.push(options[i].text);
}
// now optArray has all the text elements from the option tags.
本文标签: javascriptHow to create an array from a select list39s text using jQueryStack Overflow
版权声明:本文标题:javascript - How to create an array from a select list's text using jQuery? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://roclinux.cn/p/1744061397a2526786.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论