js动态添加div(二)...
时间:2010-08-12 来源:Cike121272604
二、动态添加Div,并在Div上添加事件
<html>
<body>
<a href="javascript:aa();">text</a>
</body>
</html>
<script language=javascript>
var divId=1;
//动态生成单纯的div
function CreateOuterDiv()
{
var obj=document.createElement("div");
obj.id="myDiv"+divId;
divId++;
obj.style.border="1px solid #000000";
obj.style.height="30px";
obj.style.width="200px";
obj.style.filter="alpha(opacity=70)";
obj.style.margin="10px";
obj.style.cursor="hand";
obj.algin="center";
//obj.innerHTML="<a href='#"+obj.id+"'>ssssssssss</a>";
obj.innerText="sssssss";
document.body.appendChild(obj);
document.getElementById(obj.id).onclick=function(){aa();};
}
function aa()
{
CreateOuterDiv();//alert();
}
</script>