js文件能否像css那样@import进来?
有什么js扩展能够导入js文件?比如我写了一些常用的js片段
tab.js
ad.js
check_login.js
...
全部js文件放在“js/”目录下,
页面如index.html中我只需写<script type="text/javascript" src="import.js"></script>
<script type="text/javascript">
import("tab.js");
import(ad.js);
</script>就能搞掂,有这样的扩展吗?
有什么js扩展能够导入js文件?比如我写了一些常用的js片段
tab.js
ad.js
check_login.js
...
全部js文件放在“js/”目录下,
页面如index.html中我只需写<script type="text/javascript" src="import.js"></script>
<script type="text/javascript">
import("tab.js");
import(ad.js);
</script>就能搞掂,有这样的扩展吗?
也可以再后台动态注册一个js文件到前台
C#中这样用Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "test", info, true);
<script src="../js/ad.js"></script>
@import js.tab;
@import js.ad;
@import js.check_login;
</script>import.js(function(){
var obj = document.getElementsByTagName("script");
var str = obj[obj.length-1].innerHTML.replace(/\./g, "/");
var arr = str.match(/[^\s+]+(?=;)/g);
for(var i=0,j=arr.length; i < j; i++){
document.write("<script src='"+arr[i]+".js'><\/script>");
}
})()
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script src="Lib.js" type="text/javascript"></script>
</head>
<body>
aaa的MD5加密结果是:
<div id="divOutput">
</div>
<script language="javascript" type="text/javascript">
//MD5.js中定义了MD5的加密方法
include("MD5.js"); //调用MD5.js中的方法
document.getElementById("divOutput").innerHTML=MD5.Compute("aaa");
</script>
</body>
</html>
这是上面这段代码的运行实际效果,感兴趣的话可以去看
http://dxlynnthsm.clidc.com/JsLib/Demo.htm