In the work often use to Select,checkbox,radio, today a little free to tidy up, lest later use when still need to find again.
Operation Select drop-down box
--Get the value or the selected item:
1, $ ("#select_id"). Change (function () {//code ...}); Add an event for Select, which is triggered when one of the items is selected
2,var checkvalue=$ ("#select_id"). Val (); Gets the value selected by select
3,var checktext=$ ("#select_id"). Find ("option:selected"). Text (); Gets the text selected by the Select
4,$ ("#columnName"). Find ("option:selected"). attr ("price");//Gets the value of the Price property in the Select selection
5,$ ("#columnName option[value= ' 3 ']"). attr ("price");//Gets the value of the property of the price of the selected item with a value of 3
6,var checkindex=$ ("#select_id"). Get (0). SelectedIndex; Gets the index value of the Select selection
7,var maxindex=$ ("#select_id option:last"). attr ("index"); Gets the maximum index value of the Select
8,$ ("#select_id option[value= ' 3 ']"). attr ("selected", true);//Depending on the item with value 3 selected
9,$ ("#select_id"). Val (' 4 '); Sets the value of 4 for the item selected
10,$ ("#select_id"). Get (0). selectedindex=2; Set the Select index value to 2 to select
11,$ ("#select_id option[text= ' jQuery ']"). attr ("selected", true); Set the text value of select to the item selected for jquery
--Add/Remove option for select:
1,$ ("#select_id"). Append ("<option value= ' value ' >Text</option>"); Append an option to the Select (drop-down item)
2,$ ("#select_id"). Prepend ("<option value= ' 0 ' > Please select </option>"); Insert an option for select (first position)
3,$ ("#select_id option:last"). Remove (); Delete index value in select maximum option (last)
4,$ ("#select_id option[index= ' 0 ']"). Remove (); Delete option with index value 0 in select (first)
5,$ ("#select_id option[value= ' 3 ']"). Remove (); Delete option for value= ' 3 ' in select
5,$ ("#select_id option[text= ' 4 ']"). Remove (); Delete option for text= ' 4 ' in select
Operation checkbox Multi Box
1,//the value of the selection can be looped out because the check box is generally selected for more than one
var payflightsts= ';
$ (' input[name= ' payflightsts_ ' +currcount+ ' "]:checked '). each (function () {
payflightsts+=$ (This). Val () + ', ';
});
2,//Gets the value of the unchecked checkbox:
$ ("Input[name= ' box ']"). each (function () {
if ($ (this). attr (' checked ') ==false) {
Alert (This). Val ());
}
});
3,//Select All
$ ("#btn1"). Click (function () {
$ ("Input[name= ' box ']"). attr ("Checked", "true");
})
4,//Cancel Select All
$ ("#btn2"). Click (function () {
$ ("Input[name= ' box ']"). Removeattr ("checked");
})
5,//return
$ ("#btn4"). Click (function () {
$ ("Input[name= ' checkbox ']"). each (function () {
if ($ (this). attr ("checked")) {
$ (this). Removeattr ("checked");
} else {
$ (this). attr ("Checked", "true");
}
})
})
Action Radio Radio Box
1
$(
, ‘input[name="testradio"]:checked‘
/ ).val();
/Get the value selected
2,//Traverse all selections with name Testraio
$(
‘input[name="testradio"]‘
).each(
function
(){
alert(
this
.value);
});