zoukankan      html  css  js  c++  java
  • js 配置基础启动文件

    页面启动文件boot.js,获取存放该文件的路径,放置通用的css,js代码,方便html页面调用。

    __CreateJSPath = function (js) {
        var scripts = document.getElementsByTagName("script");
        var path = "";
        for (var i = 0, l = scripts.length; i < l; i++) {
            var src = scripts[i].src;
            if (src.indexOf(js) != -1) {
                var ss = src.split(js);
                path = ss[0];
                break;
            }
        }
        var href = location.href;
        href = href.split("#")[0];
        href = href.split("?")[0];
        var ss = href.split("/");
        ss.length = ss.length - 1;
        href = ss.join("/");
        if (path.indexOf("https:") == -1 && path.indexOf("http:") == -1 && path.indexOf("file:") == -1 && path.indexOf("/") != 0) {
            path = href + "/" + path;
        }
        return path;
    }
    var bootPATH = __CreateJSPath("boot.js");
    var basePATH =bootPATH.split("/")[0]+"/"+ bootPATH.split("/")[2]+"/";
    document.write('<link href="' + bootPATH + 'bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css" />');
    document.write('<script src="' + bootPATH + 'jquery/jquery.min.js" type="text/javascript"></sc' + 'ript>');
    document.write('<script src="' + bootPATH + 'bootstrap/js/bootstrap.js" type="text/javascript" ></sc' + 'ript>');
    document.write('<script src="' + bootPATH + 'app/js/base.js"" type="text/javascript" ></sc' + 'ript>');
    document.write('<script src="' + bootPATH + 'jquery/json2.js"" type="text/javascript" ></sc' + 'ript>');

    项目文件结构:(如下图)

    bootPATH 就等于http://localhost:12514/Component/这个路径

    html页面调用代码:

    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
        <script src="../../boot.js" type="text/javascript"></script>
    </head>


     

  • 相关阅读:
    xml的建模
    P1341 无序字母对
    P1330 封锁阳光大学
    P2661 信息传递
    P1312 Mayan游戏
    P1514 引水入城
    C. Sad powers
    P1195 口袋的天空
    P1821 [USACO07FEB]银牛派对Silver Cow Party
    P1396 营救
  • 原文地址:https://www.cnblogs.com/lizeyan/p/3508917.html
Copyright © 2011-2022 走看看