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 ();
Jquery obtains the following values:
. Val ()
. Text ()
Set Value
. Val ('set the value here ')
$ ("document "). ready (function () {
$ ("# btn1 "). click (function () {
$ ("[name = 'checkbox']"). ATTR ("checked", 'true'); // select all
})
$ ("# btn2 "). click (function () {
$ ("[name = 'checkbox']"). removeattr ("checked"); // cancel all selections
})
$ ("# btn3 "). click (function () {
$ ("[name = 'checkbox']: Even "). ATTR ("checked", 'true'); // select all odd numbers
})
$ ("# btn4 "). click (function () {
$ ("[name = 'checkbox']"). each (function () {// reselect
if ($ (this ). ATTR ("checked") {
$ (this ). removeattr ("checked");
}< br> else {
$ (this ). ATTR ("checked", 'true');
}< BR >})
$ ("# btn5 "). click (function () {// output the selected value
var STR = "";
$ ("[name = 'checkbox'] [checked]"). each (function () {
STR + = $ (this ). val () + "\ r \ n";
// alert ($ (this ). val ();
})
alert (STR);
})