Jquery obtains the value of text, areatext, radio, checkbox, select, and other operations.

Source: Internet
Author: User

Jquery obtains the values of text, areatext, radio, checkbox, select, and other operations;
1. Suppose we have the following page:

  1. <Input Type="Text" Name="Textname" ID="Text_id" Value="">
  2. <! -- 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;

  1. Function Get_form_value(){
  2. /* Obtain the value of text. areatext */
  3. var textval =$ ( " # text_id " ) . ATTR ( " value " ) ; // or
  4. VaR Textval= $("# Text_id").Val();
  5. /* Obtain the value of the single-choice button */
  6. VaR Valradio= $("Input [@ type = radio] [@ checked]").Val();
  7. /* Obtain the value of the check box */
  8. VaR Checkboxval= $("# Checkbox_id").ATTR("Value");
  9. /* Get the value of the drop-down list */
  10. VaR Selectval= $('# Select_id').Val();
  11. }

3. Other processing of the form:

  1. // Control form elements:
  2. // Text box, text area:
  3. $ ( " # text_id " ) . ATTR ( " value " , '' ) ; // clear content
  4. $("# Text_id").ATTR("Value",'Test');// Fill in the content
  5. // Multiple choice box checkbox:
  6. $ ( " # chk_id " ) . ATTR ( " checked " , '' ) ; // unselected value
  7. $ ( " # chk_id " ) . ATTR ( " checked " , true ) ; // selected value
  8. If($("# Chk_id").ATTR('Checked')=Undefined) // Determine whether selected
  9. // Single-choice group Radio:
  10. $("Input [@ type = radio]").ATTR("Checked",'10');// Set the single-choice button with value = 10 to the selected item
  11. // Select from the drop-down list:
  12. $ ( " # Select_id " ) . ATTR ( " Value " , ' Test ' ) ; // Set value = test Project Selected item
  13. $("<Option value = 'test'> test </option> <option value = 'test2'> Test2 </option>").Appendto("# Select_id")// Add the option in the drop-down list
  14. $("# Select_id").Empty();// Clear the drop-down list


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.