1190 | 0 一枝梅 发表于 2012-6-29 09:23:21
@import url(style.css);
var style = document.createElement(’link’);
style.href = ’style.css’;
style.rel = ’stylesheet’;
style.type = ‘text/css’;
document.getElementsByTagName(’HEAD’).item(0).appendChild(style);
document.createStyleSheet(style.css);
动态的 style 节点,使用程序生成的字符串:var style = document.createElement(’style’);
style.type = ‘text/css’;
style.innerHTML=”body{ background-color:blue; }”;
document.getElementsByTagName(’HEAD’).item(0).appendChild(style);
var sheet = document.createStyleSheet();
sheet.addRule(’body’,'background-color:red’);
document.createStyleSheet(”javascript:’body{background-color:blue;’”);
<html>
<head>
<script>
function blue(){
if(document.all){
window.style="body{background-color:blue;";
document.createStyleSheet("javascript:style");
}else{
var style = document.createElement('style');
style.type = 'text/css';
style.innerHTML="body{ background-color:blue }";
document.getElementsByTagName('HEAD').item(0).appendChild(style);
}
}
</script>
</head>
<body>
<input type="button" value="blue"/>
</body>
</html>
微信号:epweike
已经有超过10万小伙伴关注了!
更多精彩好玩的活动敬请关注微信公众号