0. Environment
<input type="checkbox" value="lol"/>lol
var lol = document.getElementsByTagName("input")[0];
1. HTML DOM
a.lol.checked = true;
The value of the attribute may not be lol, as long as it is true when converted to a boolean value, there are only two types of values: true and false.
No checked mark added
b.lol.click();
The checked tag will not be added, and the value of lol.checked is true
2. DOM core
lol.setAttribute("checked","checked");
The element has added a checked tag, and the value of lol.checked is true
<input type="checkbox" checked="checked" value="lol"/>lol
In fact, the checked mark exists and is applied. The following writing method can achieve the default selection.
<input type="checkbox" checked value="lol"/>lol
When the browser parses text, it is selected by default.
The above js form elements checked and radio are selected (detailed explanation) are all the content I share with you. I hope you can give you a reference and I hope you can support Wulin.com more.