jquery Get Select Radio checkbox value

Source: Internet
Author: User

$ (#testselect option:selected '). Text ();
or $ ("#testselect"). Find (' option:selected '). Text ();
or $ ("#testselect"). Val ();
//////////////////////////////////////////////////////////////////
A bad memory can be collected:
1, dropdown box:

var cc1 = $ (". FORMC select[@name = ' country '] option[@selected]"). Text (); Get the text of the selected item in the Drop-down menu (pay attention to the middle space)
var CC2 = $ ('. FORMC select[@name = ' country '] '). Val (); Gets the value of the selected item in the Drop-down menu
var cc3 = $ ('. FORMC select[@name = ' country '] '). attr ("id"); Gets the id attribute value of the selected item in the Drop-down menu
$ ("#select"). Empty ()//Empty Drop-down box//$ ("#select"). HTML (");
$ ("<option value= ' 1 ' >1111</option>"). Appendto ("#select")//option to add a drop-down box

A little explanation:
1.select[@name = ' country '] option[@selected] Represents the Name property,
and the attribute value is the option element with the selected attribute inside the Select element of ' country ';
It can be seen that a @ begins with a property that follows.

2, Radio Box:
$ ("input[@type =radio][@checked]"). Val (); Gets the value of the selected item in the Radio box (focus on no spaces in the middle)
$ ("input[@type =radio][@value =2]"). attr ("Checked", ' checked '); Sets the value=2 of the radio box to the selected state. (Pay attention to the middle without spaces)

3, check box:
$ ("input[@type =checkbox][@checked]"). Val (); Gets the value of the first item selected in the check box
$ ("input[@type =checkbox][@checked]"). each (function () {//, because the check box is typically selected for more than one, you can cycle the output
Alert ($ (this). Val ());
});

$ ("#chk1"). attr ("Checked", "");/no tick.
$ ("#chk2"). attr ("Checked", true);/tick
if ($ ("#chk1"). attr (' checked ') ==undefined) {}//Determine whether it has been ticked

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.