我鍵入滾動(0,10,200,10); 但是當它運行時,它傳遞字符串「xxpos」或「yypos」,我確實嘗試了它沒有appostraphes,但它只是沒有工作。Javascript參數
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);
}
你給'scroller'函數的字符串作爲參數。另外,* afaik *,變量將不會從範圍'setInterval'中獲得將評估字符串。 – 2012-03-26 20:44:44
什麼是在那裏未申報的'x = 0'和'xyz = ..'? – 2012-03-26 20:44:48
也許'xyz'是另一個範圍的var,他需要停止他的間隔。但這個名字很醜陋。 – 2012-03-26 20:47:58