第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在 100 多個網(wǎng)頁的網(wǎng)站中使用 JavaScript 組件實現(xiàn) HTML

如何在 100 多個網(wǎng)頁的網(wǎng)站中使用 JavaScript 組件實現(xiàn) HTML

慕森王 2022-01-01 20:12:01
我有一個包含 200 多個網(wǎng)頁的網(wǎng)站,其中包含一個導(dǎo)航欄(標(biāo)題)。我怎樣才能自動化它,所以我不必?fù)?dān)心使用 JavaScript 更改所有 200 多個網(wǎng)頁中的標(biāo)題。實現(xiàn)這一目標(biāo)的最佳方法是什么?我已經(jīng)使用 jQuery 實現(xiàn)如下,但導(dǎo)航欄沒有顯示。    <link rel="stylesheet" href="../../assets/vendor/cubeportfolio/css/cubeportfolio.min.css">    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"        integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">        <script src="jquery.js"></script>        <script>            $(function () {                    $("#includedContent").load("../../html/home/header.html");            });        </script>    <!-- CSS Front Template -->    <link rel="stylesheet" href="../../assets/css/theme.css">    <!-- CSS Front Doc -->    <link rel="stylesheet" href="../../documentation/assets/css/starter.css"></head><body>    <!-- ========== HEADER ========== -->    <header id="includedContent"></header>    <!-- ========== END HEADER ========== -->
查看完整描述

2 回答

?
交互式愛情

TA貢獻(xiàn)1712條經(jīng)驗 獲得超3個贊

您已將此問題標(biāo)記為 PHP 和 JS,因此我強(qiáng)烈建議您在 PHP(或您可能正在使用的任何其他服務(wù)器端語言)中執(zhí)行某種常見的包含,而不是嘗試這樣做客戶端(如 smootok 所示)主要是因為它會更加可靠,但也因為它在客戶端上也會更快。

例如: <?php include("includes/header.php");?>


查看完整回答
反對 回復(fù) 2022-01-01
?
手掌心

TA貢獻(xiàn)1942條經(jīng)驗 獲得超3個贊

你可以用你想要的內(nèi)容創(chuàng)建一個新的文件頭,然后使用w3-include-html屬性包含它


例子


<div w3-include-html="header.html"></div>

添加javascript


<script>

function includeHTML() {

  var z, i, elmnt, file, xhttp;

  /* Loop through a collection of all HTML elements: */

  z = document.getElementsByTagName("*");

  for (i = 0; i < z.length; i++) {

    elmnt = z[i];

    /*search for elements with a certain atrribute:*/

    file = elmnt.getAttribute("w3-include-html");

    if (file) {

      /* Make an HTTP request using the attribute value as the file name: */

      xhttp = new XMLHttpRequest();

      xhttp.onreadystatechange = function() {

        if (this.readyState == 4) {

          if (this.status == 200) {elmnt.innerHTML = this.responseText;}

          if (this.status == 404) {elmnt.innerHTML = "Page not found.";}

          /* Remove the attribute, and call this function once more: */

          elmnt.removeAttribute("w3-include-html");

          includeHTML();

        }

      }

      xhttp.open("GET", file, true);

      xhttp.send();

      /* Exit the function: */

      return;

    }

  }

}

</script>

在頁面底部調(diào)用 includeHTML() :


<script>

includeHTML();

</script>

參考:https : //www.w3schools.com/howto/howto_html_include.asp


查看完整回答
反對 回復(fù) 2022-01-01
  • 2 回答
  • 0 關(guān)注
  • 131 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號