我想知道如何刷新/重新加载页面(甚至是特定的div)一次(!)使用jQuery?

Ideally in a way right after the DOM structure is available (cf. onload event) and not negatively affecting back button or bookmark functionality.

请注意:由于第三方的限制,replace()是不允许的.

推荐答案

Alright, I think I got what you're asking for. Try this

if(window.top==window) {
    // You're not in a frame, so you reload the site.
    window.setTimeout('location.reload()', 3000); //Reloads after three seconds
}
else {
    //You're inside a frame, so you stop reloading.
}

如果只有一次,那就这么做吧

$('#div-id').triggerevent(function(){
    $('#div-id').html(newContent);
});

如果是周期性的

function updateDiv(){
    //Get new content through Ajax
    ...
    $('#div-id').html(newContent);
}

setInterval(updateDiv, 5000); // That's five seconds

So, every five seconds the div #div-id content will refresh. Better than refreshing the whole page.

Jquery相关问答推荐

将搜索面板和服务器端与POST AJAX请求一起使用时出现DataTables错误

jQuery 时间 Select 器

在 jQuery 中构建 html 元素的最清晰方法

如何使用 jQuery 禁用粘贴(Ctrl+V)?

如何在 jQuery 中获取浏览器滚动位置?

javascript中的描述关键字

调整浏览器大小时调整jqGrid的大小?

如何禁用在div内单击

scrollIntoView 是否适用于所有浏览器?

调用 e.preventDefault() 后提交表单

将数据传递给 jQuery UI 对话框

jQuery 插件:添加回调功能

滚动 DIV 元素时如何防止页面滚动?

图片转Base64

jQuery 追加淡入

IE8 和 JQuery 的 trim()

jQuery 发送字符串作为 POST 参数

如何在文件 Select 上触发事件

如何插入元素作为第一个子元素?

detach()、hide() 和 remove() 之间的区别 - jQuery