使用 Javascript 排序下拉列表 [英] Sorting dropdown list using Javascript
本文介绍了使用 Javascript 排序下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用 javascript 对下拉项进行排序,谁能告诉我怎么做.
i want to sort the drop down items using javascript,can anyone tell me how to do this.
推荐答案
你可以使用 jQuery 和类似的东西:
You could use jQuery and something like this:
$("#id").html($("#id option").sort(function (a, b) {
return a.text == b.text ? 0 : a.text < b.text ? -1 : 1
}))
但最好问问你为什么以及你想要完成什么.
But it's probably better to ask why and what you're trying to accomplish.
这篇关于使用 Javascript 排序下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文