为什么object.onclick = GetRef("handler")不可用? object.onclick = attachEvent("onclick",new Function("GetRef('handler')")); 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 上面的有点问题object.attachEvent("onclick",new Function("GetRef('handler')")); 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> 这个是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> 我是目的在于动态指定onclick方法,而不是写死:不是: document.getElementById("button2").onclick=show2;而是:document.getElementById("button2").onclick=GetRef("show2"); 的形式用字符串动态指定。(原因是我有很多的控件,我不想一个一个慢慢的写) 给你一个函数吧,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> js如何将arr的index作为obj的属性名? 请问下面的jquery功能是什么意思? 谁对 KISSY 了解 介绍一下 万分感谢! 下面这个正则式啥意思啊??? Eaeflnr <--这是啥玩意???? 下面代码如何控制表格各单元格同时放大多少倍 js问题 document.close()方法---怎么没用的呢??? ★WEB技术新手群7437027★ DOJO的表单提交与查询数据库,前台弹出窗要如何做。。 求一网页中流媒体下载办法。 动态插入行后进行删除,无法得到动态生成的id,该如何操作得到动态的id????? 一个简单的换行问题
object.attachEvent("onclick",new Function("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>
不是: document.getElementById("button2").onclick=show2;
而是:document.getElementById("button2").onclick=GetRef("show2"); 的形式用字符串动态指定。(原因是我有很多的控件,我不想一个一个慢慢的写)
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>