Query obtains the values of text, areatext, radio, checkbox, select, and other operations;
1. Suppose we have the following page:
<Input type = "text" name = "textname" id = "text_id" value = "">
<! -- Add the rest. The important thing is to have type. Name. ID and so on. Generally, these are all available. -->
2. The following describes how to obtain various values in form;
Function get_form_value (){
/* Obtain the value of text. areatext */
VaR textval = $ ("# text_id"). ATTR ("value"); // or
VaR textval = $ ("# text_id"). Val ();
/* Obtain the value of the single-choice button */
VaR valradio = $ ("input [@ type = radio] [@ checked]"). Val ();
/* Obtain the value of the check box */
VaR checkboxval = $ ("# checkbox_id"). ATTR ("value ");
/* Get the value of the drop-down list */
VaR selectval = $ ('# select_id'). Val ();
}
3. Other processing of the form:
// Control form elements:
// Text box, text area:
$ ("# Text_id"). ATTR ("value", ''); // clear the content
$ ("# Text_id"). ATTR ("value", 'test'); // fill in the content
// Multiple choice box checkbox:
$ ("# 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
// Single-choice group Radio:
$ ("Input [@ type = radio]"). ATTR ("checked", '10'); // set the single-choice button with value = 10 to the selected item
// Select from the drop-down list:
$ ("# Select_id"). ATTR ("value", 'test'); // set the project with value = test as the selected item
$ ("<Optionvalue = 'test'> test </option> <optionvalue = 'test2'> Test2 </option> "). appendto ("# select_id") // Add the option in the drop-down box
$ ("# Select_id"). Empty (); // clear the drop-down list
4. Obtain the value of a set of Radio selected items
View plaincopy to clipboardprint?
// Obtain the value of a set of Radio selected items
VaR item = $ ('input [@ name = items] [@ checked] '). Val ();
// Obtain the text of the selected select item
VaR item = $ ("select [@ name = items] Option [@ selected]"). Text ();
// The second element in the select drop-down box is the selected value.
$ ('# Select_id') [0]. selectedindex = 1;
// The second element of the radio Radio Group is the selected value.
$ ('Input [@ name = items] '). Get (1). Checked = true;
// Obtain the value of a set of Radio selected items
VaR item = $ ('input [@ name = items] [@ checked] '). Val ();
// Obtain the text of the selected select item
VaR item = $ ("select [@ name = items] Option [@ selected]"). Text ();
// The second element in the select drop-down box is the selected value.
$ ('# Select_id') [0]. selectedindex = 1;
// The second element of the radio Radio Group is the selected value.
$ ('Input [@ name = items] '). Get (1). Checked = true;
Text Box, text area: $ ("# TXT"). ATTR ("value ");
Multiple choice box checkbox: $ ("# checkbox_id"). ATTR ("value ");
Radio Group radio: $ ("input [@ type = radio] [@ checked]"). Val ();
Drop-down box select: $ ('# sel'). 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
$ ("<Option value = '1'> 1111 </option> <option value = '2'> 2222 </option> "). appendto ("# Sel") // Add the option in the drop-down box
$ ("# Sel"). Empty (); // clear the drop-down list