Last active
March 1, 2018 06:07
-
-
Save prinsss/a12f8fe71c2e3d7a2c0fcedbc6d625d2 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
$('.load-gist').on('click', function() { | |
var gist = { | |
// URL 传参自己改下 | |
url: '//gist.github.com/printempw/' + $(this).data('hash') + '.json?callback=?', | |
dom: this | |
} | |
// 因为 URL 中带了 `callback=?`,所以这里 jQuery 会使用 JSONP 方式请求 | |
$.getJSON(gist.url, function(data) { | |
// 加载样式 | |
gist.style = document.createElement('link'); | |
gist.style.type = 'text/css'; | |
gist.style.rel = 'stylesheet'; | |
gist.style.href = data.stylesheet; | |
document.getElementsByTagName('HEAD')[0].appendChild(gist.style); | |
// 移除加载按钮 | |
$(gist.dom).after(data.div).remove(); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment