Summary of the methods of value and assignment of common HTML elements

Source: Internet
Author: User

1. Obtain a value of type text or Areatext

var textval = $ ("#text_id"). attr ("value");

var textval = $ ("#text_id"). Val ();

2. Get the value of a radio button
var Valradio = $ ("input[type=radio][checked]"). Val ();

3. Gets the value of a set of radio selected items named (items)
var item = $ (' input[@name =items][@checked] '). Val ();

4. Get the value of the check box
var checkboxval = $ ("#checkbox_id"). attr ("value");

5. Get the value of the drop-down list

var selectval = $ (' #select_id '). Val ();

6. Text box, text area
$ ("#text_id"). attr ("Value", "");//Clear Contents
$ ("#text_id"). attr ("value", ' test ');//fill content


7. Multiple marquee checkbox
$ ("#chk_id"). attr ("Checked", "");//Make it unchecked
$ ("#chk_id"). attr ("Checked", true);//tick
if ($ ("#chk_id"). attr (' checked ') ==true)//Determine if selected

8. Radio Group Radio
$ ("input[@type =radio]"). attr ("Checked", ' 2 ');//Set value=2 for the currently selected item

9. 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 ")//Add drop-down box option
$ ("#select_id"). empty ();//Empty drop-down box

10. Gets the value of a set of radio selected items named (items)
var item = $ (' input[@name =items][@checked] '). Val ();//If Unchecked, val () = undefined

11. Get the text of select selected item
var item = $ ("select[@name =items] option[@selected]"). Text ();
The second element of the Select drop-down box is the currently selected value
$ (' #select_id ') [0].selectedindex = 1;
Radio the second element of a radio group is the currently selected value
$ (' input[@name =items] '). Get (1). checked = true;

Summary of the methods of value and assignment of common HTML elements

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.