您的位置:首页 > Web前端 > JavaScript

js动态添加div(二)

2010-08-13 11:17 387 查看
二、动态添加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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: