js动态生成div和事件

来源:互联网 发布:mac怎么更新safari 编辑:程序博客网 时间:2024/05/01 08:45
<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>
0 0
原创粉丝点击