pelement.setAttribute("onclick","javascript:document.getElementById('ADDRESS').value='5225';");
换成
pelement.onclick=function(){document.getElementById('ADDRESS').value='5225';}
换成
pelement.onclick=function(){document.getElementById('ADDRESS').value='5225';}
可以用
element.onclick = function(){}这样<input type="text" id="ADDRESS" />
<div id="tdbieming"></div>
<script>
onload = function(){
var addressary = ['abcde','fjhigk'], i = 0;
var pelement = document.createElement("input");
pelement.setAttribute("type","checkbox");
pelement.setAttribute("value",addressary[i]);
//pelement.setAttribute("id","ckbbieming"+i);
pelement.id= "ckbbieming"+i; // 这样比较简洁
//pelement.setAttribute("onclick","javascript:document.getElementById('ADDRESS').value='5225';");
pelement.onclick = function(){
document.getElementById('ADDRESS').value='5225';
}
document.getElementById("tdbieming").appendChild(pelement);
}
</script>
ie下不支持这么写 在ff下测试就好的
就直接写成
pelement.onclick=function(){document.getElementById('ADDRESS').value='5225'} 还方便一些
IE不支持用setAttribute设置某些属性,网上有很多相关的文章。。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head><body>
<div id="tdbieming"></div>
<textarea id="ADDRESS"></textarea>
<script type="text/javascript">
var pelement = document.createElement("input");
pelement.setAttribute("type","checkbox");
pelement.setAttribute("value","this is value");//我随便写的值
pelement.setAttribute("id","ckbbieming"+1);//没有i,我改成1了
pelement.onclick = function(){
document.getElementById('ADDRESS').value='5225';
}
document.getElementById("tdbieming").appendChild(pelement);
</script>
</body>
</html>
...
}