Jquery 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 content
- $("# Text_id").ATTR("Value",'Test');// Fill in the content
-
- // Multiple choice box checkbox:
- $ ( " # chk_id " ) . ATTR ( " checked " , '' ) ; // unselected value
- $ ( " # chk_id " ) . ATTR ( " checked " , true ) ; // selected value
- If($("# Chk_id").ATTR('Checked')=Undefined) // Determine whether 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 value = test Project Selected item
-
- $("<Option value = 'test'> test </option> <option value = 'test2'> Test2 </option>").Appendto("# Select_id")// Add the option in the drop-down list
- $("# Select_id").Empty();// Clear the drop-down list