Drop-down Box:
Gets the text of the selected item in the Drop-down menu (note that there are spaces in the middle)
var cc1 = $ (". FORMC select[@name = ' country '] option[@selected]"). Text ();
Gets the value of the selected item in the Drop-down menu
var CC2 = $ ('. FORMC select[@name = ' country '] '). Val ();
Gets the id attribute value of the selected item in the Drop-down menu
var cc3 = $ ('. FORMC select[@name = ' country '] '). attr ("id");
Clear the dropdown box//
$ ("#select"). empty (); $ ("#select"). html (');
Option to add a drop-down box
$ ("<option value= ' 1 ' >1111</option>"). Appendto ("#select")
A little explanation:
select[@name = ' country '] option[@selected]
Represents the option element with the selected property inside a SELECT element that has the Name property and the property value is ' country '. It can be seen that a @ begins with a property that follows.
Radio Box:
Gets the value of the selected item in the Radio box (note that there are no spaces in the middle)
$ ("input[@type =radio][@checked]"). Val ();
Sets the value=2 of the radio box to the selected state. (Note that there are no spaces in between)
$ ("input[@type =radio][@value =2]"). attr ("Checked", ' checked ');
check box:
//Gets the value of the first item selected in the check box
$ ("input[@type =checkbox][@checked]"). Val ();
Because the check box is generally selected for more than one, you can loop out the
$ ("input[@type =checkbox][@checked]"). each (function () {
Alert ($ (this). Val ());
});
//Do not tick
$ ("#chk1"). attr ("Checked", "");
Tick
$ ("#chk2"). attr ("Checked", true);
Determine if
if ($ ("#chk1") has been ticked. attr (' checked ') ==undefined) {}