Jquery operation form ElementCode
/*
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
Text Box operations
Value: var textval = $ ("# text_id"). ATTR ("value ");
VaR textval = $ ("# text_id"). Val ();
Clear content: $ ("# TXT"). ATTR ("value ",");
Filling content: $ ("# TXT"). ATTR ("value", '000000 ′);
Text domain operations
Value: var textval = $ ("# text_id"). ATTR ("value ");
VaR textval = $ ("# text_id"). Val ();
Clear content: $ ("# TXT"). ATTR ("value ",");
Filling content: $ ("# TXT"). ATTR ("value", '000000 ′);
Single button operation
Value: var valradio = $ ("input [@ type = radio] [@ checked]"). Val (); // only supports one set of radio.
VaR valradio = $ ('input [@ name = chart] [@ checked] '). Val (); // in multiple groups of radio, obtain a set of values based on the name
Drop-down list
Value: var selectval = $ ('# sell'). Val ();
Set selected items: $ ("# select_id"). ATTR ("value", 'test'); // set the project with value = test as the selected item
Add new item: $ ("<option value = 'test'> test </option> <option value = 'test2'> Test2 </option> "). appendto ("# select_id") // Add the option in the drop-down box
Clear the drop-down box: $ ("# select_id"). Empty (); // clear the drop-down box
Multi-choice Box Operation
Value: $ ("# chk_id"). ATTR ("checked", ''); // value not selected
$ ("# Chk_id"). ATTR ("checked", true); // The selected value
If ($ ("# chk_id"). ATTR ('checked') = undefined) // you can check whether the selected