$ (#testselect option:selected '). Text ();
or $ ("#testselect"). Find (' option:selected '). Text ();
or $ ("#testselect"). Val ();
//////////////////////////////////////////////////////////////////
A bad memory can be collected:
1, dropdown box:
var cc1 = $ (". FORMC select[@name = ' country '] option[@selected]"). Text (); Get the text of the selected item in the Drop-down menu (pay attention to the middle space)
var CC2 = $ ('. FORMC select[@name = ' country '] '). Val (); Gets the value of the selected item in the Drop-down menu
var cc3 = $ ('. FORMC select[@name = ' country '] '). attr ("id"); Gets the id attribute value of the selected item in the Drop-down menu
$ ("#select"). Empty ()//Empty Drop-down box//$ ("#select"). HTML (");
$ ("<option value= ' 1 ' >1111</option>"). Appendto ("#select")//option to add a drop-down box
A little explanation:
1.select[@name = ' country '] option[@selected] Represents the Name property,
and the attribute value is the option element with the selected attribute inside the Select element of ' country ';
It can be seen that a @ begins with a property that follows.
2, Radio Box:
$ ("input[@type =radio][@checked]"). Val (); Gets the value of the selected item in the Radio box (focus on no spaces in the middle)
$ ("input[@type =radio][@value =2]"). attr ("Checked", ' checked '); Sets the value=2 of the radio box to the selected state. (Pay attention to the middle without spaces)
3, check box:
$ ("input[@type =checkbox][@checked]"). Val (); Gets the value of the first item selected in the check box
$ ("input[@type =checkbox][@checked]"). each (function () {//, because the check box is typically selected for more than one, you can cycle the output
Alert ($ (this). Val ());
});
$ ("#chk1"). attr ("Checked", "");/no tick.
$ ("#chk2"). attr ("Checked", true);/tick
if ($ ("#chk1"). attr (' checked ') ==undefined) {}//Determine whether it has been ticked