This article mainly introduces the implementation code of RadioButton, input, and CheckBox value assignment in jQuery. if you need it, you can refer to it and hope to help you with CheckBox.
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
$ ("11112222"). 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 {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 ("Text"); // Add an option
$ ("# Select_id"). prepend ("Select"); // 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 ();