1. jquery obtains the single-choice group radio
$ ("Input [name = 'name']: checked"). val ();
2. jquery obtains the next value of radiobutton.
$ ("Input [name = 'name']: checked"). next (). text ()
$ ("Input [name = 'name']: checked"). val ()
3. jquery obtains the input value.
$ ('# Id'). val ()
4. jquery checks the multiple choice box checkbox
$ ("# Id: checkbox"). attr ("checked ")
Value: $ ("# id"). attr ("value ");
Assign values directly to values in text () and val ().
How does JQUERY obtain the text, areatext, radio, checkbox, and select values?
$ ("Input"). val ();
$ ("Textarea"). text ();
$ ("Select"). val ();
Control form elements:
Text Box, text area: $ ("# txt"). attr ("value", ''); // clear the content
$ ("# Txt"). attr ("value", '11'); // fill in the content
Multiple choice box checkbox: $ ("# chk1"). attr ("checked", ''); // do not check
$ ("# Chk2"). attr ("checked", true); // check
If ($ ("# chk1"). attr ('checked') = undefined) // you can check whether the checked has been checked.
Radio Group radio: $ ("input [@ type = radio]"). attr ("checked", '2'); // set the project with value = 2 as the currently selected item
Drop-down box select: $ ("# sel"). attr ("value", '-sel3'); // set the value =-sel3 project to the currently selected item
$ ("<Option value = '1'> 1111 </option> <option value = '2'> 2222 </option> "). appendTo ("# sel") // Add the option in the drop-down box
$ ("# Sel"). empty (); // clear the drop-down list
JQuery obtains and sets the value of the select drop-down box. Document category:. net Programming
Obtain Select:
Obtain the selected text in the select statement:
$ ("# DdlRegType"). find ("option: selected"). text ();
Obtain the value selected by the select statement:
$ ("# DdlRegType"). val ();
Obtain the index selected by the select statement:
$ ("# DdlRegType"). get (0). selectedIndex;
Set select:
Set the index selected by select:
$ ("# DdlRegType"). get (0). selectedIndex = index; // index indicates the index value.
Set the value selected by select:
$ ("# DdlRegType"). attr ("value", "Normal");
$ ("# DdlRegType"). val ("Normal ");
$ ("# DdlRegType"). get (0). value = value;
Set select selected text:
Var count = $ ("# ddlRegType option"). length;
For (var I = 0; I <count; I ++)
{If ($ ("# ddlRegType"). get (0). options [I]. text = text)
{
$ ("# DdlRegType"). get (0). options [I]. selected = true;
Break;
}
}
$ ("# Select_id option [text = 'jquery ']"). attr ("selected", true );
Set select option items:
$ ("# Select_id"). append ("<option value = 'value'> Text </option>"); // Add an option
$ ("# Select_id"). prepend ("<option value = '0'> select </option>"); // insert an option
$ ("# Select_id option: last"). remove (); // Delete the Option with the largest index value
$ ("# Select_id option [index = '0']"). remove (); // delete an Option with an index value of 0
$ ("# Select_id option [value = '3']"). remove (); // delete an Option with a value of 3
$ ("# Select_id option [text = '4']"). remove (); // delete an Option with a TEXT value of 4
Clear Select:
$ ("# DdlRegType"). empty ();