Jquery obtains the text and value selected by select option.

Source: Internet
Author: User

Jquery radio, checkbox, select, radio, checkbox, select, and related settings

 

Obtain the value of a set of Radio selected items: var item =$ ('input [name = items] [checked] '). Val ();
Obtain the text of the selected select item: var item =$ ("select [@ name = items] Option [@ selected]"). Text ();

Obtain the text of the selected select item: var item =$ ("select [name = items] Option [selected]"). text (); or $ ("select [name = items]"). find ("option: Selected "). text ();

The second element in the select drop-down box is the selected value: $ ('# select_id') [0]. selectedindex = 1;

The Select drop-down box value = 'val' element is the current selected item: $ ("select [name = items] Option [value = 'val']"). ATTR ("selected", "selected ");

The second element of the radio Radio group is currently selected: $ ('input [@ name = items] '). get (1 ). checked = true; or $ ('input [name = items] '). ATTR ("checked", '1 ′);

The value = 'val' element of radio is currently selected: $ ('input [name = items] [value = 'val'] '). ATTR ("checked", "checked ");

Get value:

Text Box, text area: $ ("# TXT"). ATTR ("value ");

Multiple choice box checkbox: $ ("input [name = 'checkbox': checked]"). Each (function (){

Var val = $ (this). Val ();

});

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

Value of select in the drop-down box: $ ('select'). Val ();

Select the selected text value in the drop-down box: $ ("select"). Find ("option: Selected"). Text ();

Control form elements:

Text Box, text area: $ ("# TXT"). ATTR ("value", "); // clear the content

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

Multiple selection box checkbox:
The second element of the checkbox is checked: $ ("input [name = items]"). Get (1). Checked = true; // check
$ ("Input [name = items]"). Get (1). Checked = false; // do not check

Check the value = 'val 'element of the checkbox: $ ("input [name = item] [value = 'val']"). ATTR ("checked", true); or $ ("input [name = item] [value = 'val']"). ATTR ("checked", "checked ");

If ($ ("input [name = item] [value = 'val']"). ATTR ('checked') = true) // you can check whether a check is performed.

Radio Group radio: $ ("input [type = radio]"). ATTR ("checked", '2'); // set the project with value = 2 as the currently selected item

Drop-down box select: $ ("# Sel"). ATTR ("value", '-sel3'); // set the value =-sel3 project to the currently selected item

$ ("<Option value = '1'> 1111 </option> <option value = '2'> 2222 </option> "). appendto ("# Sel") // Add the option in the drop-down box

$ ("# Sel"). Empty (); // clear the drop-down list

 

Jquery obtains the value selected by radio.

Code

$ ("Input [name = 'Radio _ name'] [checked]"). Val (); // select the value of the selected radio
$ ("# Text_id"). Focus (function () {// code...}); // event triggered when the object text_id gets the focus
$ ("# Text_id"). Blur (function () {// code...}); // triggered when the focus of the object text_id is lost
$ ("# Text_id"). Select (); // set the vlaue value of the text box to the selected status.
$ ("Input [name = 'Radio _ name'] [value = 'value to select the value of Radio '").
ATTR ("checked", true); // set radio to the selected status based on the value.

Jquery obtains the value selected by the checkbox.

$ ("Input [name = 'checkbox _ name'] [checked]"); // select the set of checked checkbox elements. If you want to get the value, you need to traverse the set.
$ ("Input [name = 'checkbox _ name'] [checked]").
Each (function () {arrchk + = This. Value + ',' ;}); // traverses the set of checked checkbox elements to obtain the value.
$ ("# Checkbox_id"). ATTR ("checked"); // gets the status of a checkbox (true/false if any checkbox is selected)
$ ("# Checkbox_id"). ATTR ("checked", true); // set the status of a checkbox to select (checked = true)
$ ("# Checkbox_id"). ATTR ("checked", false); // set the status of a checkbox to unselected (checked = false)
$ ("Input [name = 'checkbox _ name']"). ATTR
("Checked", $ ("# checkbox_id"). ATTR ("checked"); // you can analyze the meaning of the code based on 3, 4, and 5.
$ ("# Text_id"). Val (). Split (","); // returns an array separated ','.

 

Jquery1.3.2

Isdark: $ ("input [@ type = radio] [name = isdark] [checked]"). Val ()

$ ("Input [name = radioname] [value = radio value]"). ATTR ("checked", "checked ");

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.