如果 DIV 值根据 ActionResult 值发生变化,则停止计时器
我将文件上传到文件夹中,并将其详细信息保存到数据库中。在执行此任务时,我正在启动计时器,插入数据后我有兴趣停止计时器。
<div id="labelUploadingStartTime" name="labelUploadingStartTime"></div>
<div id="labelUploadingEndTime" name="labelUploadingEndTime"></div>
使用以下函数,我在 labelUploadingStartTime 标签上显示开始时间。
function startUpdatingUploading_StartTimeIndicator() {
intervalIdUploadingStartTime = setInterval(
function () {
$.post(
"/MyUpload/GetStartTime",
function (progress) {
$("#labelUploadingStartTime").html(progress);
}
);
},
10
);
}
同时当在labelUploadingEndTime中设置labelUploadingStartTime值时,我使用以下函数显示倒计时详细信息。
function startUpdatingUploadingEndTimeIndicator() {
$.post(
"/MyUpload/GetStartTime",
function (progress) {
if (progress != null) {
intervalIdUploadingEndTime = setInterval(function () {
var currentTime = new Date();
var hours = currentTime.getHours();
var minutes = currentTime.getMinutes();
var seconds = currentTime.getSeconds();
// Add leading zeros
hours = (hours < 10 ? "0" : "") + hours;
minutes = (minutes < 10 ? "0" : "") + minutes;
seconds = (seconds < 10 ? "0" : "") + seconds;
// Compose the string for display
var currentTimeString = hours + ":" + minutes + ":" + seconds;
$("#labelUploadingEndTime").html(currentTimeString);
}, 1000);
}
}
);
}
现在我的兴趣是,当数据插入数据库时,我想停止计时器,并且在 labelUploadingEndTime 中我想显示结束时间。
例如,
labelUploadingStartTime --> 12:10:10
labelUploadingEndTime --> 12:12:30
我怎样才能停止计时器?
I am uploading files into the folder as well as saving their details into DB. While performing this task I am starting my timer And after inserting data I am interested to STOP the timer.
<div id="labelUploadingStartTime" name="labelUploadingStartTime"></div>
<div id="labelUploadingEndTime" name="labelUploadingEndTime"></div>
Using the below function I am displaying the START TIME on my labelUploadingStartTime label.
function startUpdatingUploading_StartTimeIndicator() {
intervalIdUploadingStartTime = setInterval(
function () {
$.post(
"/MyUpload/GetStartTime",
function (progress) {
$("#labelUploadingStartTime").html(progress);
}
);
},
10
);
}
At the same time when the labelUploadingStartTime value is set in labelUploadingEndTime I am display the countdown details using below function.
function startUpdatingUploadingEndTimeIndicator() {
$.post(
"/MyUpload/GetStartTime",
function (progress) {
if (progress != null) {
intervalIdUploadingEndTime = setInterval(function () {
var currentTime = new Date();
var hours = currentTime.getHours();
var minutes = currentTime.getMinutes();
var seconds = currentTime.getSeconds();
// Add leading zeros
hours = (hours < 10 ? "0" : "") + hours;
minutes = (minutes < 10 ? "0" : "") + minutes;
seconds = (seconds < 10 ? "0" : "") + seconds;
// Compose the string for display
var currentTimeString = hours + ":" + minutes + ":" + seconds;
$("#labelUploadingEndTime").html(currentTimeString);
}, 1000);
}
}
);
}
Now my interest is when data is inserted into the database I want to STOP THE TIMER and in labelUploadingEndTime I want to display the ending time.
For example,
labelUploadingStartTime -- > 12:10:10
labelUploadingEndTime -- > 12:12:30
How CAN I STOP THE TIMER?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要回答您的问题,您可以使用
clearInterval()
JS 函数停止计时器。您传入要停止的计时器 ID,例如:但是,我认为您根本不需要计时器。您可以使用
$.post
的success
函数将完成时间添加到其他标签。您的后端不需要返回文件上传的开始和结束时间,您在客户端拥有该信息
To answer your question, you can stop the timer with the
clearInterval()
JS function. You pass in the timer ID that you want to stop, eg:However, I don't think you need a timer at all for this. You can use the
success
function of$.post
to add the finish time to the other label.Your backend doesn't need to return the start and end times of the file upload, you have that information on the client side