javascript 高手帮助
var sha=document.createElement("div");
问如下写法有问题吗
sha.onmouseover="gao()";---------------
怎么给document.createElement加上事件

解决方案 »

  1.   

    sha.onmouseover = gao;
    function gao(){
      ;
    }
      

  2.   

    sha.onmouseover=function(){
    ...
    }
      

  3.   

    哥们 帮你写了个 动态创建 动态添加<style>
    div {border:#690 5px solid; width:100px; height:200px;}
    </style>
    </head><body onload="creat()">
    <script>
    function creat(){
    var div = document.createElement("div");
    document.body.appendChild(div);
    div.id="a"
    getdiv()

    }function getdiv(){
    if(document.getElementById("a")){
    document.getElementById("a").onclick = function(){
    alert("hello");

    }
    }

    }</script>
    </body>
      

  4.   

    function a(){
      var sha=document.createElement("div");
      sha.attachEvent('onclick', addClick);
    }function addClick(){
      alert("动态添加事件");
    }