checked = “checked” vs checked = true

后端 未结 5 1457
Happy的楠姐
Happy的楠姐 2020-12-05 04:28

What is the difference between the below two usages?

document.getElementById(\'myRadio\').checked = \"checked\";

and

docum         


        
5条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-05 04:47

    checked attribute is a boolean value so "checked" value of other "string" except boolean false converts to true.

    Any string value will be true. Also presence of attribute make it true:

    
    

    You can make it uncheked only making boolean change in DOM using JS.

    So the answer is: they are equal.

    w3c

提交回复
热议问题