Take the text of the selected item from the drop-down menu; Obtain and set the value of the drop-down menu; clear the drop-down menu; add elements to the following menu; obtain the single-choice value; select a single choice or check button; select the value of the check box, determine whether a single choice or check box is selected, whether the element is available or unavailable, and whether the element is available or unavailable.
Practical jquery operation form element code
/*
Assume that there is a button id = "save" in a form"
$ (Document). ready (function (){
$ ("# Save"). click (function (){
$ ("# Save"). attr ("disabled", true); // set to unavailable
$ ("# Form1") [0]. submit (); // It doesn't matter if you have many forms whose IDs are form1. Only the first form will be submitted.
});
});
Take the text of the selected item from the drop-down menu;
Obtain and set the value of the drop-down menu;
Clear the drop-down menu;
Add elements to the following menu;
Returns the value of a single sequence;
Select a single or multiple-choice button;
Check box value;
Determines whether a single choice or check box is selected;
The element is available and unavailable;
Determine whether the element is available or not.
1. Take the text of the selected item from the drop-down menu
$ ("# Select option [selected]"). text (); // there is a space between select and option. option is a sub-element of select.
$ ("# Select option: selected"). text (); // if it is written as $ ("# select"). text (); all the text from the drop-down menu is selected
2. Get and set the drop-down menu Value
$ ("# Select"). val (); // Value
$ ("# Select "). val ("value"); // set. If the select option has the value option, the option is selected. If the option does not exist, the select option is not changed.
3. Clear the drop-down menu
$ ("# Select"). empty ();
$ ("# Select" example .html ("");
4. add elements to the following menu
$ ('<Option value = "1"> 1 </option>'). appendto ($ ("# select "));
$ ("# Select"). append ('<option value = "1"> 1 </option> ');
5. Obtain the single-digit value.
$ ("# Id [checked]"). val ();
6. select a single choice or check button
$ ("# Id [value = val]"). attr ("checked", true); // select
$ ("# Id [value = val]"). attr ("checked", ""); // cancel the selection
$ ("# Id [value = val]"). attr ("checked", false); // cancel the selection
$ ("# Id [value = val]"). removeattr ("checked"); // cancel the selection
7. Check box Value
$ ("Input [type = checkbox] [checked]"). each (function (){
Alert ($ (this). val ());
})
// If $ ("input [type = checkbox] [checked]"). val () is used, only the first selected value is returned.
8. Determine whether a single choice or check box is selected
If ($ ("# id"). attr ("checked") {}// determine the selected
If ($ ("# id"). attr ("checked") = true) {}// judge the selected
If ($ ("# id"). attr ("checked") = undefined) {}// you can determine whether an unspecified instance is selected.
9. The element is available and unavailable.
$ ("# Id"). attr ("disabled", false); // set to available
$ ("# Id"). attr ("disabled", true); // set to unavailable
10. Determine whether the element is available or not
If ($ ("# id"). attr ("disabled") {}// judge unavailability
If ($ ("# id"). attr ("disabled") = undefined) {}// determine availability