页面如何append一个style标签

想给页面插入一段后端返回特定的样式,怎么动态插入
 

 

如果是原生js的话,可以这么写
 

var styles = document.createElement('style')
styles.appendChild(document.createTextNode('your css'))
document.documentElement.appendChild(styles)

 


<span id="t1">11</span>
<script>
    var span = document.getElementById("t1");
    // js
    span.setAttribute("style", "color: red");
    // jq
    $("#t1").css("color", "red");
    //或者
    $("#t1").style.color = "red";
</script>
var nod = document.createElement('style')
var str = 'body{background:#000;color:#fff} a{color:#fff;text-decoration:none;} a:hover{color:red;text-decoration:underline}';  
nod.type='text/css';  
if(nod.styleSheet){         //ie下  
  nod.styleSheet.cssText = str;  
} else {  
  nod.innerHTML = str;       //或者写成 nod.appendChild(document.createTextNode(str))  
}  
document.getElementsByTagName('head')[0].appendChild(nod);