如何给setInterval里的函数加参数?奇怪了 这个函数,就不应该这么用,正确的方法是:function test(param){ setInterval(function(){ alert(param) },1000);} 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <html><head> <script language="javascript"> function test(n){ alert(n); } function fu(nn) { window.setInterval("test('nn')", 1000); } </script></head><body> <button onclick="fu('shishi')">just do it</button></body></html> 先谢谢噢但是这样,我传不进来能变的变量?例如那个shishi,根本传不进来 重写一个呗:var ws = window.setInterval;window.setInterval = function(){ var foo; var time = arguments[1]; var scope = arguments[2]; if(typeof arguments[0] == "string"){ foo = new Function(arguments[0]); }else if(typeof arguments[0] == "function"){ foo = arguments[0] } var args = []; for(var i=3;i<arguments.length;i++){ args[i-3] = arguments[i]; } ws(function(){ foo.apply(scope,args) },time);}function test(a,b,c){ alert(a+b+c);}setInterval(test,3000,window,2,3,4); //参数1:函数指针 参数2:时间 参数3:作用域,默认是window 参数n(n>3):你的变量 setInterval("test("+你的变量+")",3000) 初学jquery,请教几个概念性的问题! 求一javascript函数写发 JavaScript 树形结构问题 如何用jscript读取服务器一个文件夹中的所有图片,并将这些图片添加在本地打开的一个word文档中? 谁有用js写的文章编辑器的例子 JS同步問題 求web拖拽源码 请问用javascript实现两个字符串变量的动态匹配,送分了,50 js ie currentStyle 获取样式问题 var e=window.event||arguments[0] 是什么意思啊???? 我给一个图片控件设置大小时总提示出错为何?特请教一下 split具体实现代码
<head>
<script language="javascript">
function test(n){
alert(n);
}
function fu(nn)
{
window.setInterval("test('nn')", 1000);
}
</script>
</head>
<body>
<button onclick="fu('shishi')">just do it</button>
</body>
</html>
window.setInterval = function(){
var foo;
var time = arguments[1];
var scope = arguments[2];
if(typeof arguments[0] == "string"){
foo = new Function(arguments[0]);
}else if(typeof arguments[0] == "function"){
foo = arguments[0]
}
var args = [];
for(var i=3;i<arguments.length;i++){
args[i-3] = arguments[i];
}
ws(function(){
foo.apply(scope,args)
},time);
}
function test(a,b,c){
alert(a+b+c);
}setInterval(test,3000,window,2,3,4); //参数1:函数指针 参数2:时间 参数3:作用域,默认是window 参数n(n>3):你的变量