jquery is a very powerful tool so I'm going to find it the most convenient way to hehe
Select and Delete change:
Select Check:
1.val Value:
$ ("#selectid"). Val (); The most convenient
2.text Value:
$ ("#selectid option:selected"). Text (); The most convenient
or $ ("#selectid"). Find ("option:selected"). Text ()
3.Index Value:
$ ("#selectid"). Get (0). SelectedIndex; The most convenient
Select Change:
1.val Value:
$ ("#selectid"). val ("xxx"); The most convenient
or $ ("#selectid"). attr ("value", "xxx");
2.text Value:
$ ("#selectid OPTION[TEXT=ABC]"). attr ("selected", true); The most convenient
or $ ("Selectid option:contains (XXX)"). attr ("selected", true);
3.index Value:
$ ("#select option[index=1]"). attr ("selected", true); The most convenient
Select Add:
$ ("#selectid"). Append ($ ("<opiton value= ' 0 ' > Zhang San </option>")); These two are pretty common.
$ ("#selectid"). Prepend ($ ("<opiton value= ' 0 ' > Zhang San </option>"));
Select Delete:
Empty: $ ("#selectid"). empty (); It will be emptied before normal insertion.
Partial deletion:
$ ("#selectid option:gt (0)"). Remove (); Because the first line is sometimes thead, empty.
$ ("#selectid option[value=xxx]"). Remove ();
$ ("#selectid option[text=xxx]"). Remove ();
$ ("#selectid option[index=xxx]"). Remove ();
Select does not select
$ ("#selectid"). attr ("selected", true);
$ ("#selectid"). attr ("selected", false);
Radio Search:
$ ("#radioid"). Val ();
$ ("#radioid [Name=xxx]"). Val ();
$ ("#radioid [Id=xxx]"). Val ();
Radio Change:
$ ("radioid[value=xxx]"). attr ("Checked", true);
$ ("Radioid:eq (1)"). attr ("Checked", true);
Radio Delete:
$ ("radioid"). Remove ();
CheckBox check:
$ ("#checkboxid"). Val ();
$ ("#checkboxid [Name=xxx]"). Val ();
$ ("#checkboxid [Id=xxx]"). Val ();
CheckBox change:
$ ("checkboxid[value=xxx]"). attr ("Checked", true);
$ ("Checkboxid:eq (1)"). attr ("Checked", true);
$ (": Button"). Bind ("click", Function () {
$ (": CheckBox"). each (function () {
$ (this). attr ("Checked",!$ (This). attr ("checked")); Click the button checkbox to reverse the selection;
$ (this). attr ("Checked", true); Click the button checkbox to select All;
$ (this). attr ("checked", false); Click the button checkbox is not selected;
if ($ (this). attr ("checked") ==true) {alert (this). val ())} The selected value
if ($ (this). attr ("checked") ==false) {alert (this). val ())} unchecked value
})
})
})
CheckBox Delete:
$ ("Checkboxid"). Remove ();
TXT text box check:
$ ("#txtid"). Val ();
TXT text box change:
$ ("#txtid"). Val ("xx");
txt text box Delete:
$ ("#txtid"). Val ("");
jquery Radio value, checkbox value, select Value, Radio selected, CheckBox selected, select selected, and its related
Gets the value of a set of radio selected items
var item = $ (' input[name=items][checked] '). Val ();
Gets the text of the Select selected item
var item = $ ("Select[name=items] option[selected]"). Text ();
The second element of the Select drop-down box is the currently selected value
$ (' #select_id ') [0].selectedindex = 1;
Radio the second element of a radio group is the currently selected value
$ (' input[name=items] '). Get (1). checked = true;
Get Value:
text box, text area: $ ("#txt"). attr ("value");
Multi Box checkbox:$ ("#checkbox_id"). attr ("value");
Radio Group Radio: $ ("input[type=radio][checked]"). Val ();
Drop-down box select: $ (' #sel '). Val ();
Control form elements:
text box, text area: $ ("#txt"). attr ("Value", "");//Clear Contents
$ ("#txt"). attr ("value", ' 11 ');//fill content
Multiple marquee checkbox: $ ("#chk1"). attr ("Checked", "");//No Tick
$ ("#chk2"). attr ("Checked", true);//tick
if ($ ("#chk1"). attr (' checked ') ==undefined)//Determine if a tick has been made
Radio Group Radio: $ ("Input[type=radio]"). attr ("Checked", ' 2 ');//Set value=2 for the currently selected item
Drop-down box select: $ ("#sel"). attr ("value", '-sel3 ');//Set the VALUE=-SEL3 item as the current selection
$ ("<option value= ' 1 ' >1111</option><option value= ' 2 ' >2222</option>"). AppendTo ("#sel")// option to add a drop-down box
$ ("#sel"). empty ();//Empty drop-down box