Javascript参数
我输入滚动0,10200,10; 但当它运行时,它会传递字符串xxpos或yypos,我没有使用appostraphes就尝试了它,但它就是不起作用Javascript参数,javascript,Javascript,我输入滚动0,10200,10; 但当它运行时,它会传递字符串xxpos或yypos,我没有使用appostraphes就尝试了它,但它就是不起作用 scroll = function(xpos,ypos,time,rounds){ var xxpos = xpos*1; var yypos = ypos*1; var rrounds = rounds*1; var ttime = time*1; x = 0; xyz=window.setInte
scroll = function(xpos,ypos,time,rounds){
var xxpos = xpos*1;
var yypos = ypos*1;
var rrounds = rounds*1;
var ttime = time*1;
x = 0;
xyz=window.setInterval("scroller('xxpos','yypos','ttime','rrounds')",ttime);
}
function scroller(xpos,ypos,time,rounds){
alert(xpos + ypos + time + rounds);
}
不要使用字符串,使用闭包匿名函数
window.setTimeout(function() {
scroller(xxpos, yypos, ttime, rrounds);
}, ttime);
不要使用字符串,使用闭包匿名函数
window.setTimeout(function() {
scroller(xxpos, yypos, ttime, rrounds);
}, ttime);
应该是这样的:
xyz=window.setInterval("scroller(" + xxpos + "," + yypos + "...
否则您只需传递字符串xxpos、yypos等。应该是这样的:
xyz=window.setInterval("scroller(" + xxpos + "," + yypos + "...
否则,您只需传递字符串xxpos、yypos等。您是否知道在代码中,每次调用scroll都会生成一个计时器 你的意思是把它当作一个环吗?然后:
xyz = window.setTimeout(function(){
scroller(xxpos,yypos,ttime,rrounds)
},ttime);
您是否知道,在您的代码中,每次调用scroll都会生成一个计时器 你的意思是把它当作一个环吗?然后:
xyz = window.setTimeout(function(){
scroller(xxpos,yypos,ttime,rrounds)
},ttime);
您应该使用闭包:
...
xyz = window.setInterval(function() { scroller(xxpos,yypos,ttime,rrounds); }, ttime);
...
您应该使用闭包:
...
xyz = window.setInterval(function() { scroller(xxpos,yypos,ttime,rrounds); }, ttime);
...
这是因为字符串不会成为变量 这将有助于:
window.setInterval("scroller("+ xxpos + "," + yypos + "," + ttime + "," + rrounds + ")",ttime);
或者更好:
window.setInterval(function() { scroller(xxpos, yypos, ttime, rrounds); }, ttime);
这是因为字符串不会成为变量 这将有助于:
window.setInterval("scroller("+ xxpos + "," + yypos + "," + ttime + "," + rrounds + ")",ttime);
或者更好:
window.setInterval(function() { scroller(xxpos, yypos, ttime, rrounds); }, ttime);
您可以将滚动条函数字符串作为参数。另外,在作用域setInterval中,变量将不可用。未声明的x=0和xyz=0是什么。。在那里做什么?也许xyz是另一个作用域的变量,他需要停止他的间隔。但是名字很难看,x在里面,因为我用它来查看函数运行了多少次,你只是看不到那个部分,而xyz用来停止它。我正在学习所有这些,如果它看起来如此可怕,我很抱歉。我只是在放学后的空闲时间练习制作一个javascript框架。你给滚动条函数字符串作为参数。另外,在作用域setInterval中,变量将不可用。未声明的x=0和xyz=0是什么。。在那里做什么?也许xyz是另一个作用域的变量,他需要停止他的间隔。但是名字很难看,x在里面,因为我用它来查看函数运行了多少次,你只是看不到那个部分,而xyz用来停止它。我正在学习所有这些,如果它看起来如此可怕,我很抱歉。我只是在放学后的空闲时间练习制作javascript框架。非常感谢!这成功了!真不敢相信我竟然没有想到这么明显的事情!非常感谢!这成功了!真不敢相信我竟然没有想到这么明显的事情!