Jsダイナミックスタイルの追加



<script type="text/javascript">
//      
function addStyle(content)
{
    var style;
    if(document.all)    //IE
    {
        style = document.createStyleSheet();
        style.cssText = content;
    }
    else
    {
        style = document.createElement("style"); 
        style.type = "text/css"; 
        //style.innerHTML = content;//Safari、Chrome  innerHTML  
        style.textContent = content;
    }
    try{document.getElementsByTagName("head")[0].appendChild(style);}catch(e){}//IE Error:      
}
//      
function includeStyle(url)
{
    var style = document.createElement("link");
    style.type = "text/css";
    style.setAttribute("rel","stylesheet");
    style.setAttribute("href",url);
    document.getElementsByTagName("head")[0].appendChild(style);
}
addStyle("#div1{background-color:#CC99FF;width:200px;height:100px;}");
includeStyle("http://www.mzwu.com/style/global.css");
</script>