js 配置基础启动文件
2014-01-07 15:15 无抿屎的牛牛 阅读(577) 评论(0) 编辑 收藏 举报页面启动文件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>