This article describes the JavaScript implementation of dynamic import of JS and CSS static resource files and other methods. Share to everyone for your reference. The implementation method is as follows:
/** * Dynamic import of static resource files Js/css/var $import = function () {return function (RId, res, callback) {if (res && ' Strin
G ' = = typeof res {if (rId) {if ($ (' # ' + rId '), $ (' head ')). length>0) {return;
}//Load resource file var stype = res.substring (Res.lastindexof ('. ') + 1); Support Js/css if (stype && (' js ' = Stype | |
' css ' = = stype) ' {var isscript = (stype = ' js '); var tag = ISScript?
' Script ': ' Link ';
var head = document.getElementsByTagName (' head ') [0];
Create node var linkscript = document.createelement (tag); Linkscript.type = ISScript?
' Text/javascript ': ' Text/css ';
Linkscript.charset = ' UTF-8 ';
if (!isscript) {Linkscript.rel = ' stylesheet '; } isscript?
LINKSCRIPT.SRC = Res:linkScript.href = res; if (callback && ' function ' = = typeof callback) {if (Linkscript.addeventlistener) {linkscript. AddevenTlistener (' Load ', function () {callback.call ();
}, False); else if (linkscript.attachevent) {linkscript.attachevent (' onreadystatechange '), function () {VA
R target = window.event.srcElement;
if (target.readystate = = ' complete ') {Callback.call ();
}
});
} head.appendchild (Linkscript);
}
}
};
}();
The
wants this article to help you with your JavaScript programming.