ie firefox 的 appendChild 兼容性
appendChild 这个方法在ie firefox 下是有区别的,比如在firefox 下先 createElement("input") 把type设为"checkbox",然后 appendChild 到某个节点下是没有问题的,但ie 中是不行的,我试了 checkbox radio select,这些都是不行的,但td tr没问题,后改为用 innerHTML 建哪几个不行的节点,在两个浏览器下都通过
示例:
<html>
<head>
<title></title>
<script type="text/javascript">
function setchb(){
var list_elm = document.getElementById("list");
for(var i=0; i<3; i++){
var chb_elm = document.createElement("input");
chb_elm.type = "checkbox";
chb_elm.name = "listSize";
chb_elm.value = i;
list_elm.appendChild(chb_elm);
}
}
function setchb2(){
var list_elm = document.getElementById("list");
for(var i=0; i<3; i++){
var str_chb = "<input type='checkbox' name='listSize' value='" + i + "'/>";
list_elm.innerHTML += str_chb;
}
}
function getValues(){
var listSize = document.getElementsByName("listSize");
alert(listSize.length);
for(var i=0; i<listSize.length; i++){
alert(listSize.value);
}
}
</script>
</head>
<body onload="setchb2()">
<ul id="list">
</ul>
<li><input type="button" value="getValues" onclick="getValues()"/></li>
</body>
</html>
irini
2007-04-16 23:59:34
评论:0
阅读:602
引用:0
