[英]How can I unload/load pages using jQuery?
這是我想用 jQuery 實現的目標。
問的問題
At it's simplest (and this is a gross simplification that will lose state like event handlers, iframe state, shadow DOM etc.) you "save a copy" of the page's HTML by using .html()
on the root element ( html
or body
例如)。
您可以將整個頂級元素替換為來自另一個 HTML 文件或 URL 的固定內容,方法是將數據提供給相同的.html(data)
function。
您可以使用在步驟 1 中保存的數據重復步驟 2 來恢復原始內容。
// Step 1 - save old page
const oldPage = $('html').html();
// result of fetch() or fixed HTML from file
// const newHTML = ...
// Step 2 - load new page
$('html').html(newHTML);
// Step 3 - restore old page
$('html').html(oldPage);
你可能真正想要的
如果您只關心用戶看不到舊頁面,您可能希望將所有 UI 包裝在一個可以將display
屬性設置為none
的div
中。 您也可以將新 UI 元素覆蓋在舊 UI 元素之上,可能包裹在具有純色背景的容器中(以防止舊 UI 元素通過透明背景顯示)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.