如何在页面加载时重新加载/刷新div? [英] How to reload/rfresh a div on page load?
问题描述
我有一个div块,我希望在页面加载期间自动将其刷新一次或两次.
I have a div block i want it to be automatically referrshed once or twice during when page is loading .
如何使用jquery或javascript刷新/重新加载div一次或两次?
How can refresh/reload the div once or twice using jquery or javascript?
推荐答案
我不清楚您的意思,但尝试看一下此示例
I don't know exactly what you mean but try to look this example
$(function () {
setInterval(function () {
$.ajax({
type: "POST",
cache: false,
url: "Ajax/funk.cshtml",
dataType: "text",
success: function (data) {
$('#divId').text(data);
alert('Load completed.');
}
});
}, 2000);
});
此处:
setInterval每2000毫秒执行一次操作;
jax/funk.cshtml-结果为您提供一些文本的文件(例如,在asp.net中可能仅包含@DateTime.Now
并返回时间)
here:
setInterval performs the action every 2000 milliseconds;
jax/funk.cshtml - the file which will give you some text as a result(it may contain only @DateTime.Now
for example in asp.net and will return time)
如果只想续订div,则可以对$(#somedive).onload();
使用相同的功能
或类似的东西.
if you want renew the div only once you may use the same function for $(#somedive).onload();
or something like that.
希望这会有所帮助!
这篇关于如何在页面加载时重新加载/刷新div?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!