I have jQuery but I'm not sure if it has any built-in sorting helpers. I could make a 2d array of each item's text
, value
, and selected
properties, but I don't think that javascript's built in Array.sort()
would work correctly.
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- How to toggle on Order in ReactJS
- PHP Recursively File Folder Scan Sorted by Modific
- How to fix IE ClearType + jQuery opacity problem i
Modified Tom's answer above slightly so that it actually modifies the contents of the select box to be sorted, rather than just returning the sorted elements.
jQuery function:
There's a closed jQuery ticket for a sort that should work, but just wasn't included in the core.
Referenced from a Google Groups thread, I think you just pass in a function that is used to sort, like so
Hope it helps!
This is a better solution. Declare a global function to JQuery
And call the function from the code.