JQuery operations on the drop-down box, single-choice, and multiple-choice boxes
This article mainly introduces jQuery's need for operations on the drop-down box, single-choice and multi-choice boxes. You can refer to it for help.
Drop-down box:
// Get the text of the selected item in the drop-down menu (note that there is a space in the middle)
Var C0 = $ (". formc select [@ name = 'country'] option [@ selected]"). text ();
// Obtain the value of the selected item from the drop-down list.
Var cc2 = $ ('. formc select [@ name = "country"]'). val ();
// Obtain the ID attribute value of the selected item in the drop-down list.
Var cc3 = $ ('. formc select [@ name = "country"]'). attr ("id ");
// Clear the drop-down list //
$ ("# Select"). empty (); $ ("# select" example .html ('');
// Add the option in the drop-down list
$ ("1111
"). AppendTo (" # select ")
A little explanation:
Select [@ name = 'country'] option [@ selected]
Indicates the option element with the selected attribute in the select element with the name attribute and the attribute value is 'country. It can be seen that the attribute is followed by the @ parameter.
Single region:
// Obtain the value of the selected option for a single Queue (note that there is no space in the middle)
$ ("Input [@ type = radio] [@ checked]"). val ();
// Set single vertex value = 2 to the selected state (note that there is no space in the middle)
$ ("Input [@ type = radio] [@ value = 2]"). attr ("checked", 'checked ');
Check box:
// Obtain the value of the first check box.
$ ("Input [@ type = checkbox] [@ checked]"). val ();
// Since check boxes are usually selected multiple times, you can output them cyclically.
$ ("Input [@ type = checkbox] [@ checked]"). each (function (){
Alert ($ (this). val ());
});
// Do not check
$ ("# Chk1"). attr ("checked ",'');
// Tick
$ ("# Chk2"). attr ("checked", true );
// Check whether a check has been made
If ($ ("# chk1"). attr ('checked') = undefined ){}