Javascript Argument
Javascript Argument
本文关键字:Argument Javascript 更新时间:2023-09-26
我输入滚动(0,10200,10);但当它运行时,它会传递字符串"xxpos"或"yypos",我确实尝试过它,但没有使用同位语,但它就是不起作用。
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);
应该是这样的:
xyz=window.setInterval("scroller(" + xxpos + "," + yypos + "...
否则,您只需传递字符串xxpos、yypos等。
您是否知道,在您的代码中,每次调用scroll()
都会构建一个计时器?
你的意思是把它当作一个循环吗?然后:
xyz = window.setTimeout(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);
相关文章:
- 为什么不't Javascript对我的输入值进行了一些重新检查
- 创建一个类似链接的按钮,并通过Javascript函数打开一个新的弹出窗口
- 将函数的上下文应用于javascript变量
- 使用php或javascript从facebook相册URL中删除多余的部分
- 正在添加'X'按钮,在文本字段旁边使用javascript
- 如何在JavaScript中将字符串转换为函数引用
- 模糊事件的Javascript测试
- Javascript更改图标
- 如何将HTML id分配给元素,以及如何将JavaScript应用于元素
- 如何使用WCF服务和javascript表单post上传.doc文件
- javascript结合了数组和字典
- 这是什么 ==- javascript 运算符
- 从javascript创建一个列表
- 无法在通过jQuery的ajax加载的页面中执行javascript
- Javascript events: window.event vs argument reference (funct
- javascript SyntaxError: missing ) after argument list
- Javascript: argument unpacking in function.prototype.bind()?
- Javascript Argument
- 新的ECMA5 Javascript标准中的argument. calee .name替代
- JavaScript: SyntaxError missing ) after argument list