Last active
December 12, 2018 10:08
-
-
Save fergusKe/eeed4a0ce0f598daf2bc35cb4d515c18 to your computer and use it in GitHub Desktop.
This file contains 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
var jQuery = jQuery || undefined; | |
(function($) { | |
tdFun($); | |
function tdFun($) { | |
if ($) { | |
setEvent(); | |
} else { | |
// 載入jQ | |
loadScript('https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js', function () { | |
tdFun(jQuery); | |
}); | |
} | |
// 設置事件 | |
function setEvent() { | |
console.log('設置事件'); | |
console.log('$ = ', $); | |
} | |
function loadScript(url, callback) { | |
var script = document.createElement('script'); | |
script.type = 'text/javascript'; | |
script.async = 'async'; | |
script.src = url; | |
document.body.appendChild(script); | |
if (script.readyState) { //IE | |
script.onreadystatechange = function () { | |
if (script.readyState == 'complete' || script.readyState == 'loaded') { | |
script.onreadystatechange = null; | |
callback(); | |
} | |
} | |
} else { //非IE | |
script.onload = function () { | |
callback(); | |
} | |
} | |
} | |
} | |
})(jQuery) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment