JQuery operations on the drop-down box, single-choice, and multiple-choice boxes

Source: Internet
Author: User

JQuery operations on the drop-down box, single-choice, and multiple-choice boxes

This article mainly introduces jQuery's need for operations on the drop-down box, single-choice and multi-choice boxes. You can refer to it for help.

Drop-down box:

// Get the text of the selected item in the drop-down menu (note that there is a space in the middle)

Var C0 = $ (". formc select [@ name = 'country'] option [@ selected]"). text ();

// Obtain the value of the selected item from the drop-down list.

Var cc2 = $ ('. formc select [@ name = "country"]'). val ();

// Obtain the ID attribute value of the selected item in the drop-down list.

Var cc3 = $ ('. formc select [@ name = "country"]'). attr ("id ");

// Clear the drop-down list //

$ ("# Select"). empty (); $ ("# select" example .html ('');

// Add the option in the drop-down list

$ ("1111

"). AppendTo (" # select ")

 

A little explanation:

Select [@ name = 'country'] option [@ selected]

Indicates the option element with the selected attribute in the select element with the name attribute and the attribute value is 'country. It can be seen that the attribute is followed by the @ parameter.

Single region:

// Obtain the value of the selected option for a single Queue (note that there is no space in the middle)

$ ("Input [@ type = radio] [@ checked]"). val ();

// Set single vertex value = 2 to the selected state (note that there is no space in the middle)

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

Check box:

// Obtain the value of the first check box.

$ ("Input [@ type = checkbox] [@ checked]"). val ();

// Since check boxes are usually selected multiple times, you can output them cyclically.

$ ("Input [@ type = checkbox] [@ checked]"). each (function (){

Alert ($ (this). val ());

});

// Do not check

$ ("# Chk1"). attr ("checked ",'');

// Tick

$ ("# Chk2"). attr ("checked", true );

// Check whether a check has been made

If ($ ("# chk1"). attr ('checked') = undefined ){}

Related Article

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.