The value and value assignment of jquery's main controls, including Textbox, button, lable, radio, checkbox, and selected

Source: Internet
Author: User

Textbox:
VaR STR = $ ('# TXT'). Val ();

 $ ('# TXT'). Val ("set LBL value ");

 

// Text box, text area:

$ ("# Text_id"). ATTR ("value", ''); // clear the content

$ ("# Text_id"). ATTR ("value", 'test'); // fill in the content

 

Lable: 

VaR STR = $ ('# lbl'). Text ();

$ ('# Lbl'). Text ("set LBL value ");

 

  

VaR valradio
= $ ("Input [@ type = radio] [@ checked]"). Val ();

  

VaR item
= $ ('Input [@ name = items] [@ checked] '). Val ();

 

 

VaR checkboxval
= $ ("# Checkbox_id"). ATTR ("value ");

 

  

VaR selectval
= $ ('# Select_id'). Val ();

 

// Multiple choice box checkbox:

$ ("# Chk_id"). ATTR ("checked ",'');

// Make it unchecked

$ ("# Chk_id"). ATTR ("checked", true );

// Select

If ($ ("# chk_id"). ATTR ('checked') = true)

// Determine whether selected

  

Radio Group Radio:

$ ("Input [@ type = radio]"). ATTR ("checked", '2 ');

// Set the project with value = 2 as the currently selected item

 

// Select from the drop-down list:

$ ("# Select_id"). ATTR ("value", 'test ');

// Set the project with value = test as the 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

 

Obtains the value of a set of Radio selected items named (items ).

VaR item
= $ ('Input [@ name = items] [@ checked] '). Val (); // if not selected
Then Val () = undefined

 

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 currently selected value.

$ ('Input [@ name = items] '). Get (1). Checked
= True;

 

// Reset the form

 

$ ("Form"). Each (

  Function(){ .

     Reset();

}

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.