javascript同步Import,同步調(diào)用外部js的方法
更新時間:2008年07月08日 13:11:03 作者:
javascript同步Import,同步調(diào)用外部js的實現(xiàn)代碼,測試確實可用
在線演示地址http://www.dbjr.com.cn/jslib/Import/a.html
主要功能代碼import.js
<!--
(function(){
if(typeof window._Import != "undefined") return; //防止多次加載
function _Import(uri, x) {
var f = arguments.callee.caller;
if(typeof f == "function") {
var IsIE = (navigator.userAgent.indexOf("MSIE") == -1)? false : true;
var scriptEle = document.getElementsByTagName("head")[0].appendChild(document.createElement("script"));
scriptEle.type = "text/javascript";
scriptEle.src = uri;
if (x)
{
if (IsIE) {
scriptEle.onreadystatechange = x;
}
else {
scriptEle.onload = x;
}
}
}
}
window._Import = _Import;
})();
//-->
遠程測試a.js
var a = "腳本之家www.dbjr.com.cn===";
具體調(diào)用代碼
<html>
<head>
<title>-</title>
</head>
<body>
<script type="text/javascript" src="Import.js"></script>
<script type="text/javascript">
(function(){
function callback()
{
var IsIE = (navigator.userAgent.indexOf("MSIE") == -1)? false : true;
if (IsIE)
{
if(/loaded/.test(this.readyState))
{
alert(a);
}
}
else
{
alert(a);
}
}
_Import("http://www.dbjr.com.cn/jslib/Import/a.js", callback)
})()
</script>
</body></html>
主要功能代碼import.js
復(fù)制代碼 代碼如下:
<!--
(function(){
if(typeof window._Import != "undefined") return; //防止多次加載
function _Import(uri, x) {
var f = arguments.callee.caller;
if(typeof f == "function") {
var IsIE = (navigator.userAgent.indexOf("MSIE") == -1)? false : true;
var scriptEle = document.getElementsByTagName("head")[0].appendChild(document.createElement("script"));
scriptEle.type = "text/javascript";
scriptEle.src = uri;
if (x)
{
if (IsIE) {
scriptEle.onreadystatechange = x;
}
else {
scriptEle.onload = x;
}
}
}
}
window._Import = _Import;
})();
//-->
遠程測試a.js
復(fù)制代碼 代碼如下:
var a = "腳本之家www.dbjr.com.cn===";
具體調(diào)用代碼
復(fù)制代碼 代碼如下:
<html>
<head>
<title>-</title>
</head>
<body>
<script type="text/javascript" src="Import.js"></script>
<script type="text/javascript">
(function(){
function callback()
{
var IsIE = (navigator.userAgent.indexOf("MSIE") == -1)? false : true;
if (IsIE)
{
if(/loaded/.test(this.readyState))
{
alert(a);
}
}
else
{
alert(a);
}
}
_Import("http://www.dbjr.com.cn/jslib/Import/a.js", callback)
})()
</script>
</body></html>
您可能感興趣的文章:
- 在html中引入外部js文件,并調(diào)用帶參函數(shù)的方法
- 引用外部js亂碼問題分析及解決方案
- jQuery Mobile頁面跳轉(zhuǎn)后未加載外部JS原因分析及解決
- JS加載器如何動態(tài)加載外部js文件
- jquery延遲加載外部js實現(xiàn)代碼
- Django模板變量如何傳遞給外部js調(diào)用的方法小結(jié)
- php中json_decode()和json_encode()的使用方法
- javascript:;與javascript:void(0)使用介紹
- js中cookie的使用詳細分析
- 關(guān)于js的三種使用方式(行內(nèi)js、內(nèi)部js、外部js)的程序代碼
相關(guān)文章
js傳中文參數(shù)controller里獲取參數(shù)亂碼問題解決方法
js傳中文參數(shù),在controller里獲取參數(shù)亂碼的問題在本文有個不錯的解決方法,感興趣的朋友可以參考下2014-01-01