A simple example of changing the selected state of a radio box with JS code

Source: Internet
Author: User

This article mainly introduces the JS code to change the selection of the selected state of a simple example, the need for friends can refer to

Today suddenly have a need to use, using JS code to change the selection of the Radio box.   I didn't want to either. The direct code is 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: code as follows: function Dogender (gender) {if (gender = = "Male") {Gel ("Radionan"). Style.checked = true;   else {gel ("Radionv"). Style.checked = true; One execution, or no response, a 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,!!!!!.   The code is as follows: function Dogender (gender) {if (gender = = "Male") {Gel ("Radionan"). Checked = true;   else {gel ("Radionv"). Checked = true; } }
Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.