本帖最后由 soundofsea 于 2010-07-26 18:16:32 编辑

解决方案 »

  1.   

    var ob=document.getElementById(id);
    ob.onclick=function(){xxxx};
    ob.className=xxoo;
      

  2.   

    function $addEvent(obj,type,handle){
    //事件绑定,兼容ff,ie
    if (window.addEventListener){
    obj.addEventListener(type, handle, false);
    }else if (window.attachEvent){
    obj.attachEvent("on"+type, handle);
    }else{
    obj["on" + type] = handle; 
    }
    };
    $addEvent(document.getElementById("ab"),"click",function(){alert(this.id)})
      

  3.   

    我也这样写,但总是运行到ob.onclick的时候,他就直接运行了这个onclick,所以我现在都用jQuery的bind一个click了!
      

  4.   

    你是不是写成了
    function aaa(){xxxx};
    ob.onclick= aaa();