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
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