jquery gets the value of each element of the form

Source: Internet
Author: User

Radio Value Acquisition

$ ("input[type= ' Radio ']:checked"). Val ();

2, sets the specified item as the currently selected item

$ ("input[type= ' Radio ')"). EQ (1). attr ("Checked", true);//Set the second item to be selected

<input type= "text" name= "Textname" id= "text_id" value= "" >
<!--the rest please add it yourself. It is important to have TYPE.NAME.ID and so on, the general situation these are some--

2. Below to see how to obtain the various values in the form and so on;

function Get_form_value () {
/ * Get the value of Text.areatext * /
var textval = $ ("#text_id"). attr ("value");//or
var textval = $ ("#text_id"). Val ();
/ * Get the value of the radio button * /
var Valradio = $ ("input[@type =radio][@checked]"). Val ();
/ * Get 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. Additional processing of the form:

//Control form elements:
//text box, text area:
$ ("#text_id"). attr ("Value", "");//Clear Contents
$ ("#text_id"). attr ("value", ' test ');//fill content
//Multi marquee checkbox:
$ ("#chk_id"). attr ("Checked", "");//Unchecked Value
$ ("#chk_id"). attr ("Checked", true);//The selected value
if ($ ("#chk_id"). attr (' checked ') ==undefined)//Determine if selected
//Radio Group radio:
$ ("input[@type =radio]"). attr ("Checked", ' 10 ');//The radio button setting value=10 is the current selection
//drop-down box select:
$ ("#select_id"). attr ("value", ' test ');//Set Value=test item as the current selection
$ ("<option value= ' test ' >test</option><option value= ' test2 ' >test2</option>"). AppendTo ("#select_id")//option to add a drop-down box
$ ("#select_id"). empty ();//Empty drop-down box

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.