您将如何动态订购< option select>列表使用JQuery? [英] How would you dynamically order an <option select> list using JQuery?
本文介绍了您将如何动态订购< option select>列表使用JQuery?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我有一个下拉列表和一个列表框,是否可以使用JQuery根据该下拉列表对列表框进行排序?一个例子会有所帮助.
If I have a dropdown and a listbox, is there a way to order the listbox based on the dropdown using JQuery? An example would be helpful.
推荐答案
这会更改下拉菜单中的顺序.您必须根据自己的条件设置订单:
This alters the order in the pulldown. You'll have to set the order depending on your own criteria:
<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>
这篇关于您将如何动态订购< option select>列表使用JQuery?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文