<script type="text/javascript"> 
function newtag(){ 
    var o = document.createElement("div"); 
    document.getElementById("fuck").appendChild(o); 
    o.style.position = "absolute";
    o.style.width = 200; 
    o.style.height = 200; 
    o.style.left = 100; 
    o.style.top = 100; 
    o.style.zIndex = 10000; 
    o.style.backgroundColor = "red"; 
    o.onclick = new Function("alert(\"fuck\")"); 

</script>

解决方案 »

  1.   

    1、少了 o.style.position = "absolute";
    2、定义 onclick 时,应该是 o.onclick = new Function("alert(\"fuck\")"); 
      

  2.   

    1、少了 o.style.position = "absolute"; 
    2、定义 onclick 时,应该是 o.onclick = new Function("alert(\"fuck\")"); 
    正确
      

  3.   

    style.width, style.left .... 后面是有单位的, 上面朋友说的 绝对定位也很重要否则 设置 top 或left没意义... 还有 onclick=function(){alert(111)}这样表现的...
    帮你改了,供参考
    <html xmlns="http://www.w3.org/1999/xhtml" > 
    <head> 
        <title>Untitled Page </title> 
    <script type="text/javascript"> 
    function newtag(){ 
        var o = document.createElement("div"); 
        document.getElementById("fuck").appendChild(o); 
    o.parentNode.style.position = "relative";
    o.style.position = "absolute";
        o.style.width = 200 + 'px'; 
        o.style.height = 200 + 'px'; 
        o.style.left = 100 + 'px'; 
        o.style.top = 100 + 'px'; 
        o.style.zIndex = 10000; 
        o.style.backgroundColor = "red"; 
        o.onclick = function(){
    alert("fuck"); 
    }

    </script> 
    </head> 
    <body> 
    <div id="fuck" style=" width:400px; height:400px; background-color: Black" > 
    </div> 
    <script type="text/javascript"> 
    newtag(); 
    </script> 
    </body> 
    </html> 
      

  4.   

     o.style.position = "absolute";
    o.onclick = new Function("alert(\"fuck\")"); 
      

  5.   

    少了position = "absolute";属性,onclick赋值应赋函数名,或者匿名函数
    <script type="text/javascript"> 
    function newtag(){ 
        var o = document.createElement("div"); 
        document.getElementById("fuck").appendChild(o); 
        o.style.position = "absolute";
        o.style.width = 200; 
        o.style.height = 200; 
        o.style.left = 100; 
        o.style.top = 100; 
        o.style.zIndex = 10000; 
        o.style.backgroundColor = "red"; 
        o.onclick = function(){alert("fuck")};

    </script>
      

  6.   

    要把父DIV当作位置参照必须将他的position 设为 "absolute"