Browser Quirk: Dynamically appended checked checkbox does not appear checked (IE
程序员文章站
2022-07-16 08:43:23
...
Problem
Dynamically appended checkbox element does not appear checked despite setting the checked property state to true or "checked".
Browser
Internet Explorer
Example
The Javascript code:
Expand
|
Select
|
Wrap
|
Line Numbers
- var cb = document.createElement("input");
- cb.type = "checkbox";
- cb.name = "checkbox1";
- cb.id = "cbID";
- cb.checked = true;
- obj.appendChild(cb);
Solution
Use defaultChecked instead of checked:
Expand
|
Select
|
Wrap
|
Line Numbers
- cb.defaultChecked = true;
Alternative Solution
Set the checked state after appending the checkbox:
Expand
|
Select
|
Wrap
|
Line Numbers
- obj.appendChild(cb);
- cb.checked = true;
上一篇: dom4j的基本操作
下一篇: dom4j的基本操作