为什么我在javascript中动态添加的checkbox无法选中呢

来源:百度知道 编辑:UC知道 时间:2024/06/14 04:47:26
代码如下
var box=document.createElement("input")
box.setAttribute("type","checkbox")

box.setAttribute("name","a")
document.body.appendChild(box)
最后生成了一个checkbox,但是无法选中
我的不行啊,点击没有反应

<script type="text/javascript">
var box=document.createElement("input")
box.setAttribute("type","checkbox")
box.setAttribute("id","a")
document.body.appendChild(box)

function oo()
{
var c=document.getElementById("a")
if(c.getAttribute("checked"))
{

alert("选中")
}
else
{
alert("未选中")
}

}

</script>

可以选中啊