我想调用showUpload();从两个setTimeouts内。两者都不起作用。这似乎超出了范围,我不知道为什么。我试过this.showUpload()
也没有工作。javascript setTimeout函数超出范围
$(document).ready(function(){
var progress_key = $('#progress_key').val();
// this sets up the progress bar
$('#uploadform').submit(function() {
setTimeout("showUpload()",1500);
$("#progressbar").progressbar({ value:0}).fadeIn();
});
// uses ajax to poll the uploadprogress.php page with the id
// deserializes the json string, and computes the percentage (integer)
// update the jQuery progress bar
// sets a timer for the next poll in 750ms
function showUpload() {
$.get("/myid/videos/uploadprogress/" + progress_key, function(data) {
if (!data)
return;
var response;
eval ("response = " + data);
if (!response)
return;
var percentage = Math.floor(100 * parseInt(response['bytes_uploaded'])/parseInt(response['bytes_total']));
$("#progressbar").progressbar({ value:percentage})
});
setTimeout("showUpload()", 750);
}
});
谢谢你的时间。
意图是对的,尽管描述有点偏离,但您正在使用括号调用方法,但是您尝试在全局空间中调用一个方法时,它是一个字符串......它不会“不存在,像你这样的直接引用是正确的方法。 – 2010-05-28 00:41:28
@Nick:谢谢你的提示......我只是想找一些关于'setTimeout()'作为字符串传递时代码的参考。 – 2010-05-28 00:50:47
谢谢。它现在有效。 – Keyo 2010-05-28 00:50:54