如何给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 如何定位动态创div 用javascript从数据库里取出为YYYY-MM-DD的日期格式 <a name=>的使用问题。。 判断客户端是否安装 0ffice 如何用回车代替tab,且焦点转移方向改为垂直? 请教高人! 100分 document.open传参数问题 我给一个图片控件设置大小时总提示出错为何?特请教一下 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):你的变量