我在更新jQuery进度条时遇到了一些问题。该进度条是不是页面加载时的文档中,我加入它只是当一个按钮,用户点击,丁是这样的:更新在运行时添加的JQuery进度栏
$(this).parent().append('<div class="progressbar"></div>');
$(this).parent().children('div.progressbar').show();
$(this).parent().children('div.progressbar').progressbar({value: 20});
然后,使用超时,我想更新它
function updateProgressBar() {
$('.progressbar').each(function() {
myNewValue = getNewValue();
$(this).progressbar('value', 50);
});
setTimeout('updateProgressBar()', 5000);
}
setTimeout('updateProgressBar()', 5000);
调试控制台抱怨说:“未捕获:不能调用进度的方法来initialiaztion之前:试图调用方法‘价值’” 谷歌搜索在这里我发现,问题可能涉及到inizialization进度条后加载页面
有人可以帮我吗?
在此先感谢
- 编辑 -
感谢布莱恩,我想你的解决方案,但我不能为我工作
现在我已经这个代码
function startProgress() {
$(this).parent().append('<div class="progressbar"></div>');
$(this).siblings('.progressbar').show();
$(this).siblings('.progressbar').progressbar({value: 0});
function updateProgress() {
$('.progressbar').each(function() {
myNewValue = getNewValue($(this).parent().parent().attr('id'));
$(this).progressbar('value', myNewValue);
});
setTimeout('updateProgress', 5000);
}
setTimeout('updateProgress', 5000);
}
The console is sayng there's no updateProgress defined
- edit -
很多很多谢谢!
现在我的作品相当明确的版本...
这里我当前的代码
if($(this).siblings('.progressbar').size() == 0) {
$(this).parent().append('<div class="progressbar"/>');
$(this).siblings('.progressbar').progressbar({value: 0});
}
$(this).siblings('.progressbar').show();
function updateProgress() {
$('.progressbar').each(function() {
myParams = 'service=' + $(this).parent().parent().attr('id') + '&content=' + $(this).parent().attr('id')
myUrl = '/datacast/content_progress/?' + myParams;
theValue = $(this).progressbar('value');
$.get(myUrl, {}, function(aReply) {
myData = aReply.split(' ');
myItemId = myData[0];
myValue = parseInt(myData[1]);
try {
$(".item[id = " + myItemId + "]").children(".progressbar").progressbar('value', myValue);
}
catch(myError) {
//alert(myError);
}
})
});
setTimeout(updateProgress, 5000);
}
setTimeout(updateProgress, 5000);
正如你可以看到我已经添加了一个控件,如果已经有一个进度条我多次通过该代码。 进度条每次更新,但控制台笙歌说:“类型错误:无法调用‘应用’未定义”,所以我不得不用空卡位体加入try块砸错误。该网页的工作,但如果你有一个想法,为什么有这个错误
你使用的是什么插件? – lonesomeday 2010-11-02 16:16:50
我使用jquery-1.4.2.js和jQuery UI进度条1.7.2 – thrantir 2010-11-03 11:20:38
在下面检查我的新答案。 – rossipedia 2010-11-03 21:33:37