Html頁(yè)面內(nèi)引入抽取出來的Html埠帕,js垢揩,css示例

在寫純Html網(wǎng)站的時(shí)候,每個(gè)頁(yè)面的頭部菜單敛瓷、js叁巨、css和底部說明都是同樣的,有的時(shí)候你要改琐驴,就要一個(gè)一個(gè)的去改俘种,通過下面方法將這些相同的抽取出來秤标,方便后期維護(hù)!
  希望能幫到你~宙刘!
在applyBusiness.html頁(yè)面引入公共頁(yè)頭header.html苍姜。

1、applyBusiness.html:

<!DOCTYPE html>
<html>
  <head>
    <title>我的申請(qǐng)任務(wù)</title>
    <script type="text/javascript" charset="utf-8" src="../../../js/platform/system/header.js"></script>
  </head>
  <body>
      <div class="container">
         <div class="mainBody mt-20 applyBusiness">
             <form class="form-inline mt-30" id="searchFormId">
               <div class="clearfix">
                   <div class="form-group col-sm-4 col-md-4 padding-0">
                        <label class="text-right labelBlock">科信業(yè)務(wù)事項(xiàng):</label>
                        <select id="businessType" name="businessType" class="form-control optionLength">
                                <option> </option>
                            <option value="104" servicetype="1">故障申報(bào)</option><option value="105" servicetype="2">服務(wù)申請(qǐng)</option>
                        </select>
                    </div>
                    <div class="form-group col-sm-4 col-md-4 padding-0">
                        <label class="text-right labelBlock">狀態(tài):</label>
                        <select id="serviceStatus" name="serviceStatus" class="form-control optionLength">
                                <option value="all">全部</option>
                                <option value="pending">待提交</option>
                                <option value="handling">辦理中</option>
                                <option value="completed">已辦結(jié)</option>
                       </select>
                    </div>
                    <div class="form-group col-sm-4 col-md-4 padding-0">
                        <label class="text-right labelBlock">業(yè)務(wù)來源:</label>
                        <select id="serviceSource" name="serviceSource" class="form-control optionLength">
                       </select>
                    </div>
               </div>
                <div class="clearfix mt-20">
                    <div class="col-sm-5 col-md-5 halfWidth">
                        <div class="form-group" id="applyTime1">
                            <label class="text-right" for="startApplyDate">申請(qǐng)時(shí)間:</label>
                            <input type="text" readonly="readonly" size="16" value="" id="startApplyDate" name="startApplyDate" class="form-control form_date" data-date-format="yyyy-mm-dd">
                        </div>
                        <div class="form-group" id="applyTime2">
                            <label for="endApplyDate">-</label>
                            <input type="text" readonly="readonly" size="16" value="" id="endApplyDate" name="endApplyDate" class="form-control form_date" data-date-format="yyyy-mm-dd">
                        </div>
                    </div>
                    <div class="col-sm-2 col-md-2 margin-top-20">
                        <button id="search-btn" type="button" class="btn btn-primary btn-warning marginLeft">搜索</button>
                        <button type="button" id="resetId" class="btn btn-primary btnIp">重置</button>
                    </div>
                </div>
            </form>
            <table style="margin-top:30px" id="table"></table>
        </div>
      </div>
    </body>
</html>

2悬包、header.js:

/**
 * 引用JS和CSS頭文件
 */
var rootPath = getRootPath(); //項(xiàng)目路徑

/**
 * 動(dòng)態(tài)加載CSS和JS文件
 */
var dynamicLoading = {
    meta : function(){
        document.write('<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">');
    },
    css: function(path){
        if(!path || path.length === 0){
            throw new Error('argument "path" is required!');
        }
        document.write('<link rel="stylesheet" type="text/css" href="' + path + '">');
    },
    js: function(path, charset){
        if(!path || path.length === 0){
            throw new Error('argument "path" is required!');
        }
        document.write('<script charset="' + (charset ? charset : "utf-8") + '" src="' + path + '"></script>');
    }
};

/**
 * 取得項(xiàng)目路徑
 * @author wul
 */
function getRootPath() {
    //取得當(dāng)前URL
    var path = window.document.location.href;
    //取得主機(jī)地址后的目錄
    var pathName = window.document.location.pathname;
    var post = path.indexOf(pathName);
    //取得主機(jī)地址
    var hostPath = path.substring(0, post);
    //取得項(xiàng)目名
    var name = pathName.substring(0, pathName.substr(1).indexOf("/") + 1);
    return hostPath + name + "/";
}

//動(dòng)態(tài)生成meta
dynamicLoading.meta();

//動(dòng)態(tài)加載項(xiàng)目 JS文件
dynamicLoading.js(rootPath + "/js/common/jquery-1.9.1.min.js", "utf-8");
dynamicLoading.js(rootPath + "/js/common/bootstrap.min.js", "utf-8");
dynamicLoading.js(rootPath + "/js/process/center/common/baseApp.js", "utf-8");
dynamicLoading.js(rootPath + "/js/process/center/common/bootstrap-datetimepicker.min.js", "utf-8");
dynamicLoading.js(rootPath + "/js/process/center/common/bootstrap-datetimepicker.zh-CN.js", "utf-8");
dynamicLoading.js(rootPath + "/js/process/center/common/jquery.dataTables.js", "utf-8");
dynamicLoading.js(rootPath + "/js/platform/system/loadHeader.js", "utf-8");

//動(dòng)態(tài)加載項(xiàng)目 CSS文件
dynamicLoading.css(rootPath + "/css/common/bootstrap-3.3.5/css/bootstrap.min.css");
dynamicLoading.css(rootPath + "/css/common/bootstrap-3.3.5/css/bootstrap-responsive.css");
dynamicLoading.css(rootPath + "/css/workflow/css/jquery.dataTables.css");
dynamicLoading.css(rootPath + "/css/workflow/css/newWorkflow.css");
3衙猪、loadHeader.js 
$(function(){
    $(".container").append('<div id="header"></div>');
    $("#header").load(getRootPath() + "header.html");
});

4、header.html

<nav class="navbar navbar-default navbar-fixed-top navWhole">
     <div class="container-fluid">
         <!-- Brand and toggle get grouped for better mobile display -->
         <div class="navbar-header">
             <button type="button" class="navbar-toggle collapsed navToggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
                 <span class="sr-only">Toggle navigation</span>
                 <span class="icon-bar"></span>
                 <span class="icon-bar"></span>
                 <span class="icon-bar"></span>
             </button>
           <a class="navbar-brand" href="#">![](./images/process/center/top/gongan.png)</a>
           <p class="navbar-text navHeader">科信服務(wù)門戶</p>
         </div>

         <!-- Collect the nav links, forms, and other content for toggling -->
         <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
             <ul class="nav navbar-nav navbar-right navToggle">
                 <li><a href="./index.html">首頁(yè) </a></li>
                 <li class="dropdown">
                     <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">個(gè)人服務(wù)中心 <span class="caret"></span></a>
                     <ul class="dropdown-menu">
                         <li><a href="newWorkflow/personalManage/applyBusiness/html" target="_blank">我申請(qǐng)的業(yè)務(wù)</a></li>
                         <li><a href="newWorkflow/personalManage/dealBusiness/html">我經(jīng)辦的業(yè)務(wù)</a></li>
                     </ul>
                 </li>
                 <li class="dropdown">
                     <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">服務(wù)管理中心 <span class="caret"></span></a>
                     <ul class="dropdown-menu">
                         <li><a href="newWorkflow/serviceManage/businessFlowManage/html" target="_blank">業(yè)務(wù)表單管理</a></li>
                         <li><a href="newWorkflow/serviceManage/businessReportManage/html" target="_blank">業(yè)務(wù)流程管理</a></li>
                     </ul>
                 </li>
             </ul>
         </div><!-- /.navbar-collapse -->
     </div><!-- /.container-fluid -->
 </nav>
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末布近,一起剝皮案震驚了整個(gè)濱河市垫释,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌撑瞧,老刑警劉巖棵譬,帶你破解...
    沈念sama閱讀 217,084評(píng)論 6 503
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場(chǎng)離奇詭異预伺,居然都是意外死亡订咸,警方通過查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,623評(píng)論 3 392
  • 文/潘曉璐 我一進(jìn)店門酬诀,熙熙樓的掌柜王于貴愁眉苦臉地迎上來脏嚷,“玉大人,你說我怎么就攤上這事瞒御「感穑” “怎么了?”我有些...
    開封第一講書人閱讀 163,450評(píng)論 0 353
  • 文/不壞的土叔 我叫張陵肴裙,是天一觀的道長(zhǎng)趾唱。 經(jīng)常有香客問我,道長(zhǎng)践宴,這世上最難降的妖魔是什么鲸匿? 我笑而不...
    開封第一講書人閱讀 58,322評(píng)論 1 293
  • 正文 為了忘掉前任,我火速辦了婚禮阻肩,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘运授。我一直安慰自己烤惊,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,370評(píng)論 6 390
  • 文/花漫 我一把揭開白布吁朦。 她就那樣靜靜地躺著柒室,像睡著了一般。 火紅的嫁衣襯著肌膚如雪逗宜。 梳的紋絲不亂的頭發(fā)上雄右,一...
    開封第一講書人閱讀 51,274評(píng)論 1 300
  • 那天空骚,我揣著相機(jī)與錄音,去河邊找鬼擂仍。 笑死囤屹,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的逢渔。 我是一名探鬼主播肋坚,決...
    沈念sama閱讀 40,126評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼,長(zhǎng)吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼肃廓!你這毒婦竟也來了智厌?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 38,980評(píng)論 0 275
  • 序言:老撾萬榮一對(duì)情侶失蹤盲赊,失蹤者是張志新(化名)和其女友劉穎铣鹏,沒想到半個(gè)月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體哀蘑,經(jīng)...
    沈念sama閱讀 45,414評(píng)論 1 313
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡诚卸,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,599評(píng)論 3 334
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了递礼。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片惨险。...
    茶點(diǎn)故事閱讀 39,773評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖脊髓,靈堂內(nèi)的尸體忽然破棺而出辫愉,到底是詐尸還是另有隱情,我是刑警寧澤将硝,帶...
    沈念sama閱讀 35,470評(píng)論 5 344
  • 正文 年R本政府宣布恭朗,位于F島的核電站,受9級(jí)特大地震影響依疼,放射性物質(zhì)發(fā)生泄漏痰腮。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,080評(píng)論 3 327
  • 文/蒙蒙 一律罢、第九天 我趴在偏房一處隱蔽的房頂上張望膀值。 院中可真熱鬧,春花似錦误辑、人聲如沸沧踏。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,713評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽翘狱。三九已至,卻和暖如春砰苍,著一層夾襖步出監(jiān)牢的瞬間潦匈,已是汗流浹背阱高。 一陣腳步聲響...
    開封第一講書人閱讀 32,852評(píng)論 1 269
  • 我被黑心中介騙來泰國(guó)打工, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留茬缩,地道東北人赤惊。 一個(gè)月前我還...
    沈念sama閱讀 47,865評(píng)論 2 370
  • 正文 我出身青樓,卻偏偏與公主長(zhǎng)得像寒屯,于是被迫代替她去往敵國(guó)和親荐捻。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,689評(píng)論 2 354

推薦閱讀更多精彩內(nèi)容

  • 問答題47 /72 常見瀏覽器兼容性問題與解決方案寡夹? 參考答案 (1)瀏覽器兼容問題一:不同瀏覽器的標(biāo)簽?zāi)J(rèn)的外補(bǔ)...
    _Yfling閱讀 13,751評(píng)論 1 92
  • 發(fā)現(xiàn) 關(guān)注 消息 iOS 第三方庫(kù)处面、插件、知名博客總結(jié) 作者大灰狼的小綿羊哥哥關(guān)注 2017.06.26 09:4...
    肇東周閱讀 12,098評(píng)論 4 62
  • 1.在本篇文章中我學(xué)到的最重要的概念:①相信團(tuán)隊(duì)的力量菩掏,②要合理的安排時(shí)間和工作魂角,③堅(jiān)持才有收獲。 2.讓我怦然心...
    17數(shù)427穆聰敏閱讀 178評(píng)論 2 2
  • 2016年已經(jīng)過去智绸, 北京的冬天雖然冷的異常野揪, 卻依舊沒有下幾場(chǎng)雪, 自從買了水彩瞧栗,每周都會(huì)畫幾幅斯稳,偶然看到別人畫...
    曾小兮閱讀 2,609評(píng)論 4 32
  • 有人跟我說,建深锤岸,你是現(xiàn)實(shí)主義者竖幔。 我變了嗎?我一直追求自己喜歡的是偷,好玩有趣的拳氢,我一直跟從內(nèi)心。 他們說蛋铆,這是精致...
    Bekey閱讀 661評(píng)論 0 0