相关疑难解决方法(0)

使用javascript控制css适用于Mozilla和Chrome但不适用于IE

我在使用与Internet Explorer一起使用css(使用文本变量)的函数时遇到了问题,但它适用于Firefox和Chrome.

代码:

/*! addCssStyle() applies the text value $CssText$ to the the specified document
$Doc$ e.g. an IFrame; or if none specified, default to the current document,
*/function addCssStyle(CssText, Doc){

//Secure $Head$ for the current $Doc$
    Doc = Doc||document;    var head = Doc.getElementsByTagName('head')[0];
    if(!head || head == null){
        head = Doc.createElement('div');    Doc.body.appendChild(head);
    } if(!head || head == null){return false;}

//createElement('style')
    var PendingStyle = Doc.createElement('style');
//  if (is_gecko){PendingStyle.href = 'FireFox.css';}//???needeed???
    PendingStyle.type = 'text/css';
    PendingStyle.rel = 'stylesheet';
//  PendingStyle.media = 'screen';//???needeed??? …
Run Code Online (Sandbox Code Playgroud)

javascript internet-explorer webkit google-chrome

6
推荐指数
1
解决办法
2264
查看次数