Using JS code to change the selected state of a simple example _javascript tips

Source: Internet
Author: User

Today suddenly have a need to use, using JS code to change the selection of the Radio box. And I didn't want to go straight

Copy Code code as follows:

function Dogender (gender) {
if (gender = = "Male") {
Gel ("Radionan"). style.checked = "Checked";
} else {
Gel ("Radionv"). style.checked = "Checked";
}
}

function Gel (ID) {
return document.getElementById (ID);
}


One execution, no response ...

Because we set the check in the radio tag to be checked= "checked", so subconsciously to gel ("Radionv"). Style.checked assigned to "checked", and then the Internet to check

Originally in the JS code to select the Radio box to give checked value to true.

Continue to read:

Copy Code code as follows:

function Dogender (gender) {
if (gender = = "Male") {
Gel ("Radionan"). Style.checked = true;
} else {
Gel ("Radionv"). Style.checked = true;
}
}

One implementation, or no response, a little bit of a mask ... What's wrong????

Isn't it a style attribute????

Direct Gel ("Radionan") to click, you can see the checked property.

That's right,!!!!!.

Copy Code code as follows:

function Dogender (gender) {
if (gender = = "Male") {
Gel ("Radionan"). Checked = true;
} else {
Gel ("Radionv"). Checked = true;
}
}

As a matter of execution, it is true that ...

It's all over!!!!!!!!!!!!

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.