JS getattribute Get Checkbox/radio checked value is different in each browser

Source: Internet
Author: User

JS getattribute Get Checkbox/radio checked value is different in each browser
E6/7: Return false/true in turn

IE8: Returns an empty string in turn/checked

Ie9/10/firefox/safari/chrome/opera: Returns the null/empty string in turn

Input[type=radio] In the same situation as above, similar Boolean properties are: Autofocus|autoplay|async|checked|controls|defer|disabled|hidden|loop|multiple |open|readonly|required|scoped|selected
<! DOCTYPE html>
<meta charset= "Utf-8"/>
<body>
<input type= "checkbox"/>
<input type= "checkbox" checked/>

<script>
var checkboxs = document.getelementsbytagname (' input ');
Alert (Checkboxs[0].getattribute (' checked '));
Alert (Checkboxs[1].getattribute (' checked '));
</script>
</body>
</HTML>

Note: To determine whether Checkbox/radio is selected, use the property instead of using attribute.

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.