Get checked items
gets the value of the selected item
$ ("#select1"). Val ();
gets the text of the selected item
$ ("#select1 option:selected"). Text ();
or
$ ("#select1"). Find ("option:selected"). Text ();
gets the index of the selected item
$ ("#select1"). Get (0). SelectedIndex;
Set the selection
Select by Value
The option to set a value of 2 selects
$ ("#select1"). Val (2);
Select by text
Set Text to test option selected
//This is the wrong wording
$ ("#select1 option[text= ' test ']"). attr ("selected", true);
Input supports this way to get a property value: "Input[text= ' Test '"
//Select Requires "option:contains (' Test ')" to get
//correctly written
$ ("# Select1 option:contains (' Test ') "). attr (" selected ", true);
or
$ ("#select1"). Find ("option:contains (' Test ')"). attr ("selected", true)
Follow index to select
Select the third item
$ ("#select1"). Get (0). selectedindex=2;
Select Select Event Change, not click
$ ("#select1"). Change (function () {
Console.log (the selected value is: + $ (this). Val ());
});
Add/Remove option items for select
$ ("#select_id"). Append ("<option value= ' value ' >Text</option>"); Appends an option (Drop-down)
$ ("#select_id") to the Select. Prepend ("<option value= ' 0 ' > Please select </option>"); Inserts an option (first position)
$ ("#select_id option:last") for the Select. Remove (); Deletes the maximum index value option (the last)
$ ("#select_id option[index= ' 0 ']") of the Select. Remove (); Deletes option (first)
$ ("#select_id option[value= ' 3 ']" with index value of 0 in the Select. Remove (); Delete option
$ ("#select_id option[text= ' 4 ') of value= ' 3" in the Select). Remove (); Delete option $ ("#select_id") for text= ' 4 ' in the Select
. empty ();/Clear dropdown box
get and set the radio selected value for the Radio box
Gets the value of a set of radio selected Items
= $ (' input[name=items][checked] '). Val ();
The second element of the radio Radio Group is the currently selected value
$ (' input[name=items] '). Get (1). checked = true;
The item to set VALUE=2 is currently selected
$ ("Input[type=radio]"). attr ("Checked", ' 2 ');
get and set multiple-selection box check values
$ ("#chk1"). attr ("Checked", ""); Do not tick
$ ("#chk2"). attr ("Checked", true);//Tick
if ($ ("#chk1"). attr (' checked ') ==undefined)//judge whether it has been ticked
Reference
Http://www.cnblogs.com/zhangym118/p/5509673.html