Created
October 22, 2015 01:52
-
-
Save keenwon/cfe75aa7a3743037f486 to your computer and use it in GitHub Desktop.
js动态加载css
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
'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