使用Javascript排序下拉列表 [英] Sorting dropdown list using Javascript

查看:102
本文介绍了使用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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆