开发者

How do I gather dropdown values into array with jQuery? [duplicate]

开发者 https://www.devze.com 2023-02-02 07:37 出处:网络
This question already has answers here: Closed 11 years ago. Possible Duplicate: How to get all options of a select using Jquery?
This question already has answers here: Closed 11 years ago.

Possible Duplicate:

How to get all options of a select using Jquery?

I have the following code I need to gather all the possible options into a 2D array d开发者_运维问答etailing 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());
});
0

精彩评论

暂无评论...
验证码 换一张
取 消