Skip to content

Instantly share code, notes, and snippets.

@fergusKe
Last active December 12, 2018 10:08
Show Gist options
  • Save fergusKe/eeed4a0ce0f598daf2bc35cb4d515c18 to your computer and use it in GitHub Desktop.
Save fergusKe/eeed4a0ce0f598daf2bc35cb4d515c18 to your computer and use it in GitHub Desktop.
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