The property has only one value for this type of HTML property, and how to set the value; for example: checked = "checked" vs checked = True

Source: Internet
Author: User

Reference Link: https://stackoverflow.com/questions/10650233/checked-checked-vs-checked-true

Ask:

1 What's the difference between the below and the usages? 2 3 document.getElementById (' MyRadio '). Checked = "Checked"; 4  and 5 6 document.getElementById (' MyRadio '). Checked = true; 7 for me, both is behaving the same. But, I am just curious to know why there exist and methods to do the same. 8 9 Which one would be the ideal usage? I need to support IE7 and higher versions.
View Code

For:

1 document.getElementById (' MyRadio '). Checked is a Boolean value. It should be true or False23document.getElementById (' MyRadio '). Checked = "checked"; casts The string to a Boolean, which is true. 4 5 document.getElementById (' MyRadio '). Checked = true; just assigns true without casting. 6 7 Use True as it was marginally more efficient and was more intention revealing to maintainers.
View Code

document.getElementById (' MyRadio '). Checked is a Boolean value . It's supposed to be real or fake.

document.getElementById (' MyRadio '). Checked = "Checked"; Converts a string to a Boolean value, which is correct.

document.getElementById (' MyRadio '). Checked = true; Just assign true without projecting.

Use True because it is a bit more efficient and more intended for maintainers to show.

So setting the value of this single attribute to True or false is the right one .

The property has only one value for this type of HTML property, and how to set the value; for example: checked = "checked" vs checked = True

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.