document.getElementById('abcd').onDblclick=function()
{alert("2");}//这样写为啥不行?

解决方案 »

  1.   


    <html>
    <body>
    </body>
    <script language="JavaScript">
    <!--
    var oDiv = document.createElement("div");
    oDiv.style.border = "1 solid red";
    oDiv.innerHTML="AA"
    oDiv.ondblclick = function(){alert("ok")}
    document.body.appendChild(oDiv)
    //-->
    </script>
    </html>
      

  2.   

    var s=document.createElement('div'); 
    s.id='abcd';
    document.getElementById("容器").appendChild(s);
    document.getElementById('abcd').ondblclick=function()
    {
    alert("");
    }
      

  3.   

    <html>
      <head>
        <title>abcd</title>
        <script type="text/javascript">
          window.onload = function() {
            var aEle = document.getElementById("a");
            var bEle = document.createElement("div");
            bEle.id="b";
            bEle.style.border="1px red groove";
            bEle.style.width="100px";
            bEle.style.height="100px";
            aEle.appendChild(bEle);
            bEle.ondblclick="alert()";
          }
        </script>
      </head>
      <body>
        <div id="a">
          div=a
        </div>
      </body>
    </html>