javascript没有更新变量
本文关键字:变量 更新 javascript | 更新日期: 2023-09-27 18:00:20
我有一个asp.net应用程序,我正在尝试创建一个与系统一起运行的进度条,我正在使用Java Script来完成更新进度,我想知道如何在下面的代码中更新var update = 0;
和这个$("#progressbar").progressbar('value', update);
而不使用for循环,因为我已经准备好使用for循环和布尔,系统会抛出一个长时间运行的进度错误。其余的java脚本代码都很糟糕,我想将其更新到值60;
被称为的JavaScript
$.updateProgressbar = function () {
//Calling PageMethod for current progress
PageMethods.OperationProgress(function (result) {
//Updating progress
$("#progressbar").progressbar('value', result.progress)
//If operation is complete
if (result.progress == 100) {
//Enable button
$("#Confirm_btn").attr('disabled', '');
}
//If not
else {
//Reset timer
setTimeout($.updateProgressbar, 10);
}
});
};
$(document).ready(function () {
//Progressbar initialization
$("#progressbar").progressbar({ value: 0 });
//Button click event
$("#Confirm_btn").click(function (e) {
e.preventDefault();
//Disabling button
$('#error').text("");
$("#Confirm_btn").attr('disabled', 'disabled');
var update = 0;
//Making sure that progress indicate 0
$("#progressbar").progressbar('value', update);
//Call PageMethod which triggers long running operation
PageMethods.Operation(function (result) {
if (result) {
//Updating progress
$("#progressbar").progressbar('value', result.progress)
//Setting the timer
setTimeout($.updateProgressbar, 5);
}
});
});
});
您可以使用setInterval
重复调用一个函数,因此该函数可以触发ajax函数或简单地更新progressBar。这不会阻止你的程序。