我有一個自動刷新按鈕,當按鈕開啓時,我的網頁的特定部分應該刷新。例如,如果我有一個DIV,當按鈕爲ON時,此DIV中的內容應該重新加載。如果該按鈕處於關閉狀態,則DIV應保持不變。如何刷新我的網頁的特定部分?
我只有當自動刷新按鈕在整個頁面的編碼是令人耳目一新。是否有可能刷新網頁的特定部分?
這裏是我的編碼: -
var int=self.setInterval(function(){refreshPage()},60000);
$(document).ready(function() {
var hashTag = window.location.href.split('#');
if (hashTag[1] == 'reload') {
$('#refresh').addClass('refresh-on').html('');
}
$('#refresh').on('click', function() {
$(this).toggleClass('refresh-on');
if ($(this).hasClass('refresh-on'))
$(this).html('Refresh On');
else
$(this).html('Refresh Off');
});
});
function refreshPage() {
if ($('#refresh').hasClass('refresh-on')) {
location.hash = 'reload';
window.location.reload();
} else
location.hash = '';
}
除I幀和圖像,如何能在瀏覽器重裝只是一個網頁的一部分?如果您有辦法在應用程序中執行此操作,則需要使用AJAX專門定義它。 – Barmar
@Barmer:謝謝兄弟! –