如何使用Javascript添加CSS?如何添加CSS规则(例如strong { color: red })使用Javascript?
                    
                    
                3 回答
 
                    
                    
                            白猪掌柜的
                            
                                
                            
                        
                        
                                                
                    TA贡献1893条经验 获得超10个赞
style
// Your CSS as textvar styles = `
    .qwebirc-qui .ircwindow div { 
        font-family: Georgia,Cambria,"Times New Roman",Times,serif;
        margin: 26px auto 0 auto;
        max-width: 650px;
    }
    .qwebirc-qui .lines {
        font-size: 18px;
        line-height: 1.58;
        letter-spacing: -.004em;
    }
    .qwebirc-qui .nicklist a {
        margin: 6px;
    }
`var styleSheet = document.createElement("style")styleSheet.type = "text/css"styleSheet.innerText = styles
document.head.appendChild(styleSheet) 
                    
                    
                            白衣染霜花
                            
                                
                            
                        
                        
                                                
                    TA贡献1796条经验 获得超10个赞
innerHTML
function insertCss( code ) {
    var style = document.createElement('style');
    style.type = 'text/css';
    if (style.styleSheet) {
        // IE
        style.styleSheet.cssText = code;
    } else {
        // Other browsers
        style.innerHTML = code;
    }
    document.getElementsByTagName("head")[0].appendChild( style );}添加回答
举报
0/150
	提交
		取消
	