【问题标题】:How would you dynamically order an <option select> list using JQuery?您将如何使用 JQuery 动态排序 <option select> 列表?
【发布时间】:2010-10-14 05:15:25
【问题描述】:

如果我有一个下拉列表和一个列表框,有没有办法使用 JQuery 根据下拉列表对列表框进行排序?举个例子会很有帮助。

【问题讨论】:

    标签: jquery


    【解决方案1】:

    这会改变下拉菜单的顺序。您必须根据自己的标准设置顺序:

    <select id="the-select">
        <option value="1">First option</option>
        <option value="2">Second option</option>
    </select>
    
    <script type="text/javascript">
    //<![CDATA[
        $(function (){
            $("#the-select option[value=2]").insertBefore("#the-select option[value=1]");
        });
    //]]>
    </script>
    

    【讨论】:

      猜你喜欢
      • 2013-05-30
      • 2019-02-09
      • 2019-01-28
      • 1970-01-01
      • 2022-01-27
      • 2010-12-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多