jquery on dropdown box, radio box, multi-selection box operation _jquery

Source: Internet
Author: User

Drop-down Box:

Gets the text of the selected item in the Drop-down menu (note that there are spaces in the middle)
var cc1 = $ (". FORMC select[@name = ' country '] option[@selected]"). Text ();
Gets the value of the selected item in the Drop-down menu
var CC2 = $ ('. FORMC select[@name = ' country '] '). Val ();
Gets the id attribute value of the selected item in the Drop-down menu
var cc3 = $ ('. FORMC select[@name = ' country '] '). attr ("id");
Clear the dropdown box//
$ ("#select"). empty (); $ ("#select"). html (');
Option to add a drop-down box
$ ("<option value= ' 1 ' >1111</option>"). Appendto ("#select")

A little explanation:

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

Represents the option element with the selected property inside a SELECT element that has the Name property and the property value is ' country '. It can be seen that a @ begins with a property that follows.

Radio Box:

Gets the value of the selected item in the Radio box (note that there are no spaces in the middle)
$ ("input[@type =radio][@checked]"). Val ();
Sets the value=2 of the radio box to the selected state. (Note that there are no spaces in between)
$ ("input[@type =radio][@value =2]"). attr ("Checked", ' checked ');

check box:

//Gets the value of the first item selected in the check box
$ ("input[@type =checkbox][@checked]"). Val ();
Because the check box is generally selected for more than one, you can loop out the
$ ("input[@type =checkbox][@checked]"). each (function () {
Alert ($ (this). Val ());
});
//Do not tick
$ ("#chk1"). attr ("Checked", "");
Tick
$ ("#chk2"). attr ("Checked", true);
Determine if
if ($ ("#chk1") has been ticked. attr (' checked ') ==undefined) {}

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.