Skip to content

Instantly share code, notes, and snippets.

@keenwon
Created October 22, 2015 01:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save keenwon/cfe75aa7a3743037f486 to your computer and use it in GitHub Desktop.
Save keenwon/cfe75aa7a3743037f486 to your computer and use it in GitHub Desktop.
js动态加载css
'use strict';
module.exports = function (cssText) {
if (!cssText) {
return;
}
var head = document.head || document.getElementsByTagName('head')[0],
style = document.createElement('style');
style.type = 'text/css';
if (style.styleSheet) {
style.styleSheet.cssText = cssText;
} else {
style.appendChild(document.createTextNode(cssText));
}
head.appendChild(style);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment