CSS——建立css

來源:互聯網
上載者:User

標籤:

        CreateInlineStyle: function () {   //建立一個內聯樣式表            var style = document.createElement(‘style‘); //建立一個style元素            var head = document.head || document.getElementsByTagName(‘head‘)[0]; //擷取head元素            style.type = ‘text/css‘; //這裡必須顯示設定style元素的type屬性為text/css,否則在ie中不起作用            head.appendChild(style); //把建立的style元素插入到head中                return style;        },        GetInlineStyle: function () {   //擷取一個內聯樣式表; 從後往前搜尋            var head = document.head || document.getElementsByTagName(‘head‘)[0]; //擷取head元素            var children=head.children;            var inlineStyle = null;            for (var i = children.length - 1; i >= 0; i--) {                var node = children[i];                if (node.tagName == "STYLE" && node.type == "text/css") {                    inlineStyle = node;                    break;                }            }            if (!inlineStyle) {  //不存在內聯式的樣式表則建立                inlineStyle = this.CreateInlineStyle();            }            return inlineStyle;        },        AddInlineCSS: function (cssText) {            var style = this.GetInlineStyle();            if (style.styleSheet) { //IE                var func = function () {                    try { //防止IE中stylesheet數量超過限制而發生錯誤                        style.styleSheet.cssText = cssText;                    } catch (e) {                        console.log("stylesheet數量超過限制!");                    }                }                //如果當前styleSheet還不能用,則放到非同步中則行                if (style.styleSheet.disabled) {                    setTimeout(func, 10);                } else {                    func();                }            } else { //w3c                //w3c瀏覽器中只要建立文本節點插入到style元素中就行了                var textNode = document.createTextNode(cssText);                style.appendChild(textNode);            }        }

使用:

var cssRowAltBackColor = cssSelect + " tr.datagrid-row-alt{ background-color:" + customStyle.rowAltBackColor + "}";
BA.AddInlineCSS(cssRowAltBackColor);

CSS——建立css

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.