Home >Web Front-end >JS Tutorial >Discussion on the issue of default selection of checkbox created by JS in IE_javascript skills

Discussion on the issue of default selection of checkbox created by JS in IE_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:19:151010browse

Test browsers: ie8 (compatible and incompatible modes), ff6.

Copy code The code is as follows:

var chk = document.createElement("input");
chk.setAttribute("type","checkbox");
container.appendChild(chk);
chk.setAttribute("checked",true);

Above The code does not always work in ie8 compatibility mode and ff6, but it does not work in ie8 incompatibility mode. It only works after appendChild and then setting the checked value, as follows:
Copy code The code is as follows:

var chk = document.createElement("input");
chk.setAttribute("type ","checkbox");
chk.setAttribute("checked",true);
container.appendChild(chk);

It seems that the above paragraph is reversed.
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn