如何使用jQuery将下拉值收集到数组中? [英] How do I gather dropdown values into array with jQuery?
本文介绍了如何使用jQuery将下拉值收集到数组中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能重复:
如何使用Jquery获取选择的所有选项?
Possible Duplicate:
How to get all options of a select using Jquery?
我有以下代码,我需要将所有可能的选项收集到2D数组中,详细说明所显示的值和文本.
I have the following code I need to gather all the possible options into a 2D array detailing the value and the text shown.
<div class="input-box">
<select name="options[4]" id="select_4">
<option value="">-- Please Select --</option>
<option value="24">Not Sure - Send Me Some Samples First </option>
<option value="13">1 Jet Black </option>
<option value="14">Blondette 4/27 </option>
<option value="15">Boho Blonde 613/12 </option>
<option value="16">Caramel 6 </option>
<option value="17">Cherry 530 </option>
<option value="18">Dirty Blonde 612/12 </option>
<option value="19">Ebony Black 1b </option>
<option value="20">Hot Toffee 4 </option>
<option value="21">LA Blond 24/613 </option>
<option value="22">Malibu Blonde 60/613 </option>
<option value="23">Raven 2 </option>
</select>
</div>
我真的不确定如何做到这一点,到目前为止,我通常会尝试一下,但我知道它没有用.
I am really not sure how to do this, I would normally give my attempt so far but I know its less than useful.
myarray = $('.input-box').eq(0).val();
推荐答案
好的,我知道了.感谢您的帮助!
OK, I figured it out. Thanks for the help guys!
$j('.input-box:eq(0) option').each(function() {
alert($j(this).val()+' :: '+$j(this).text());
});
这篇关于如何使用jQuery将下拉值收集到数组中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文