How to maintain the selected order of chosen and pass the value by selected order

前提是你 提交于 2019-12-12 20:18:48

问题


<div>
    <em><label for="multiple-label-example">Click to Highlight Multiple Select</label></em>
    <select id="multiple-label-example" name="cond-fields[]" tabindex="-1" style="width: 350px; display: none;" class="chosen-select" multiple="" data-placeholder="Your Favorite Types of Bear">
        <option value=""></option>
        <option>American Black Bear</option>
        <option>Asiatic Black Bear</option>
        <option>Brown Bear</option>
        <option selected="">Giant Panda</option>
        <option>Sloth Bear</option>
        <option>Sun Bear</option>
        <option>Polar Bear</option> 
        <option>Spectacled Bear</option>
    </select>
    <div class="chosen-container chosen-container-multi" style="width: 350px;" title="" id="multiple_label_example_chosen">
        <ul class="chosen-choices">
            <li class="search-choice"><span>Giant Panda</span>
                <a class="search-choice-close" data-option-array-index="4"></a>
            </li>
            <li class="search-field">
                <input type="text" style="width: 25px;" autocomplete="off" class="" value="Your Favorite Types of Bear" tabindex="18">
            </li>
        </ul>
        <div class="chosen-drop">
            <ul class="chosen-results">
                <li class="active-result" style="" data-option-array-index="1">American Black Bear</li>
                <li class="active-result" style="" data-option-array-index="2">Asiatic Black Bear</li>
                <li class="active-result" style="" data-option-array-index="3">Brown Bear</li>
                <li class="result-selected" style="" data-option-array-index="4">Giant Panda</li>
                <li class="active-result" style="" data-option-array-index="5">Sloth Bear</li>
                <li class="active-result" style="" data-option-array-index="6">Sun Bear</li>
                <li class="active-result" style="" data-option-array-index="7">Polar Bear</li>
                <li class="active-result" style="" data-option-array-index="8">Spectacled Bear</li>
            </ul>
        </div>
    </div>
</div>

how to maintain the selected order of chosen. i select the following order in my form Brown Bear, Asiatic Black Bear , Giant Panda , American Black Bear

but it passing value like the following

cond-fields[]  - American Black Bear
cond-fields[]  - Asiatic Black Bear
cond-fields[]  - Brown Bear
cond-fields[]  - Giant Panda

how to maintain the selected order and pass the value by selected order , the demo link is http://harvesthq.github.io/chosen/


回答1:


This question has already been addressed here:

  • Chosen jQuery plugin : get multiple select values in the order they were clicked
  • Chosen: Keep Multiple Selection Order


来源:https://stackoverflow.com/questions/25266287/how-to-maintain-the-selected-order-of-chosen-and-pass-the-value-by-selected-orde

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!