1. Get Selected items:
Copy Code code as follows:
Gets the value of the selected item:
$ (' Select#sel option:selected '). Val ();
Or
$ (' Select#sel '). Find (' option:selected '). Val ();
Gets the text value of the selected item:
$ (' select#seloption:selected '). Text ();
Or
$ (' Select#sel '). Find (' option:selected '). Text ();
2. Gets the index value of the currently selected item:
Copy Code code as follows:
$ (' Select#sel '). Get (0). SelectedIndex;
3. Get the maximum index value for the current option:
Copy Code code as follows:
$ (' Select#sel option:last '). attr ("index")
4. Get the length of the DropDownList:
Copy Code code as follows:
$ (' Select#sel ') [0].options.length;
Or
$ (' Select#sel '). Get (0). Options.length;
5. Set the first option to the selected value:
Copy Code code as follows:
$ (' Select#sel option:first '). attr (' selected ', ' true ')
Or
$ (' Select#sel ') [0].selectedindex = 0;
6. Set the last option to the selected value:
Copy Code code as follows:
$ (' Select#sel option:last). attr (' selected ', ' true ')
7. Set any option to the selected value based on the index value:
Copy Code code as follows:
$ (' Select#sel ') [0].selectedindex = index value; index value =0,1,2 ....
8. Set the VALUE=4 option to the selected value:
Copy Code code as follows:
$ (' Select#sel '). attr (' Value ', ' 4 ');
Or
$ ("Select#sel option[value= ' 4 ']"). attr (' selected ', ' true ');
9. Option to delete value=3:
Copy Code code as follows:
$ ("Select#sel option[value= ' 3 ']"). Remove ();
10. Delete the first few option:
Copy Code code as follows:
$ ("Select#sel option"). EQ (index value). Remove (); index value =0,1,2 ....
If you delete a 3rd radio:
$ ("Select#sel option"). EQ (2). Remove ();
11. Delete the first option:
Copy Code code as follows:
$ ("Select#sel option"). EQ (0). Remove ();
Or
$ ("Select#sel Option:first"). Remove ();
12. Delete last option:
Copy Code code as follows:
$ ("Select#sel option:last"). Remove ();
13. Delete DropDownList:
Copy Code code as follows:
$ ("Select#sel"). Remove ();
14. Add an option after the select:
Copy Code code as follows:
$ ("Select#sel"). Append ("F");
15. Add an option before the select:
Copy Code code as follows:
$ ("Select#sel"). Prepend ("0");
16. Traverse option:
Copy Code code as follows:
$ (' select#sel option '). each (function (index, domele) {
Write code
});