Created
August 6, 2015 03:27
-
-
Save gu-fan/756b93d58c87f1297310 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ; | |
| (function() { | |
| /** | |
| * 动态加载js文件 | |
| * @param {string} url js文件的url地址 | |
| * @param {Function} callback 加载完成后的回调函数 | |
| */ | |
| var _getScript = function(url, callback) { | |
| var head = document.getElementsByTagName('head')[0], | |
| js = document.createElement('script'); | |
| js.setAttribute('type', 'text/javascript'); | |
| js.setAttribute('src', url); | |
| head.appendChild(js); | |
| //执行回调 | |
| var callbackFn = function(){ | |
| if(typeof callback === 'function'){ | |
| callback(); | |
| } | |
| }; | |
| if (document.all) { //IE | |
| js.onreadystatechange = function() { | |
| if (js.readyState == 'loaded' || js.readyState == 'complete') { | |
| callbackFn(); | |
| } | |
| } | |
| } else { | |
| js.onload = function() { | |
| callbackFn(); | |
| } | |
| } | |
| } | |
| //如果使用的是zepto,就添加扩展函数 | |
| if(Zepto){ | |
| $.getScript = _getScript; | |
| } | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment