object.onclick = attachEvent("onclick",new Function("GetRef('handler')"));

解决方案 »

  1.   

    上面的有点问题
    object.attachEvent("onclick",new Function("GetRef('handler')"));
      

  2.   

    object.onclick = GetRef("handler")
    这个我测试了下,是没问题的
    <input name=button1 type=button value="换函数" onclick=huan()>
    <input name=button3 type=button value="换回去" onclick=huan2()>
    <input name=button2 type=button value="执行函数" onclick=show()>
    <script language=javascript>
    function show()
    {
    alert("haha");
    }
    function show2(a)
    {
    alert(a)
    alert("我换了");
    }
    function huan()
    {
    document.getElementById("button2").onclick=show2("111");
    }
    function huan2()
    {
    document.getElementById("button2").onclick=show();
    }
    </script>
      

  3.   

    这个是VBSCRIPT里的<SCRIPT LANGUAGE="VBScript">Function GetRefTest()   Dim Splash   Splash = "GetRefTest Version 1.0"   & vbCrLf   Splash = Splash & Chr(169) & " YourCompany 1999 "   MsgBox SplashEnd FunctionSet Window.Onload = GetRef("GetRefTest")</SCRIPT>
      

  4.   

    我是目的在于动态指定onclick方法,而不是写死:
    不是: document.getElementById("button2").onclick=show2;
    而是:document.getElementById("button2").onclick=GetRef("show2"); 的形式用字符串动态指定。(原因是我有很多的控件,我不想一个一个慢慢的写)
      

  5.   

    给你一个函数吧,function GetRef(func){
    return new Function( func+"();" );
    }------------------------------
    <input name=button2 type=button value="执行函数">
    <script language=javascript>
    var show = function(){alert('函数1')};
    function GetRef(func){
    return new Function( func+"();" );
    }
    document.getElementsByTagName("input")[0].onclick=GetRef("show");
    </script>