<div id= "myDIV"> chickMe</div>
<script   type="text/javascript">
obj=document.getElementById("myDIV");
obj.onclick = show;
function show()
{
    alert( "dd ");
}
</script> 

解决方案 »

  1.   

    <div id="myDIV">chickMe</div>
    <script type= "text/javascript">
    obj=document.getElementById("myDIV");
    obj.onclick=show;
    function show()
    {
        alert( "dd ");
    }
    </script> 
      

  2.   

    各位大侠,不要那么快回答,请问你们测试了吗?
    我要求是兼容ie和firefox
    其中还是鼠标单击事件
      

  3.   

    你试试吧
    至少
    IE6.0和Firefox/2.0.0.7是可以执行的
      

  4.   

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title> new document </title>
    <meta name="generator" content="editplus" />
    <meta name="author" content="" />
    <meta name="keywords" content="" />
    <meta name="description" content="" />
    </head><body>
    <div id="bb" class="bd" style="cursor:pointer">click me
    </div>
    <script type="text/javascript">
    <!--
    function addEvent(el,eventType,fn){
    if(el.addEventListener){
    el.addEventListener(eventType,fn,false);
    }else if(el.attachEvent){
    el.attachEvent("on" + eventType,fn);
    }else{
    el["on"+eventType]=fn;
    }
    } var b = document.getElementById('bb')
    addEvent(b,'click',funname)function funname(){
    alert(1)
    }
    //-->
    </script>
    </body>
    </html>
      

  5.   

    不好意思,是兼容的
    是我测试的条件不同,所以有不同的结果<div id= "myDIV"> chickMe</div>
    <script   type="text/javascript">
    obj=document.getElementById("myDIV");
    i=10;
    obj.onclick = show(i);
    function show(i)
    {
        alert(i);
    }
    </script> 这样为什么不行??
      

  6.   

    obj.onclick = show(i);
    i 从哪里来啊。这样写没法给事件传参数啊。
      

  7.   

    问题解决
    <div id= "myDIV"> chickMe</div>
    <script   type="text/javascript">
    obj=document.getElementById("myDIV");
    i=10;
    obj.onclick =function(){ show(i)};
    function show(i)
    {
        alert(i);
    }
    </script>