javascript同步Import,同步調用外部js的方法
更新時間:2008年07月08日 13:11:03 作者:
javascript同步Import,同步調用外部js的實現(xiàn)代碼,測試確實可用
在線演示地址http://www.fzitv.net/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.fzitv.net===";
具體調用代碼
<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.fzitv.net/jslib/Import/a.js", callback)
})()
</script>
</body></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.fzitv.net===";
具體調用代碼
復制代碼 代碼如下:
<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.fzitv.net/jslib/Import/a.js", callback)
})()
</script>
</body></html>
相關文章
微信小程序網(wǎng)絡層封裝的實現(xiàn)(promise, 登錄鎖)
這篇文章主要介紹了微信小程序網(wǎng)絡層封裝(promise, 登錄鎖),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2019-05-05

