我正在使用 JQuery 為我的網站創建“應用程式”。我不知道將 html 檔案拉入字串的正確語法,以便應用程式按鈕打開一個視窗,其中包含 html 檔案。
我試圖在一個函式中重寫這個字串變數:
$('.openbuttonapp').dblclick(function () {
var $objWindow = $('<div > Put me in, Coach! </div>');
看起來像這樣:
var entireDocumentHTMLAsAString = document.documentElement.innerHTML;
$('.openbuttonapp').dblclick(function () {
var $objWindow = $(entireDocumentHTMLAsAString);
entireDocumentHTMLAsAString旨在成為我檔案夾中的 .html。我需要正確使用此語法的提示,以便我可以復制我需要的 html 檔案。
在 Github 上查看完整專案:https ://github.com/sosophia10/TimeCapsule (參見 js/experience.js)
uj5u.com熱心網友回復:
您可以只fetch()使用 HTML 源檔案的內容。在以下示例中,我使用了公開可用的 HTML 源代碼:
const url="https://baconipsum.com/api/?type=all-meat¶s=3&start-with-lorem=1&format=html";
fetch(url).then(r=>r.text()).then(html=>document.querySelector("div").innerHTML=html)
<div></div>
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/534768.html
