例 4.16. 放大段落文字
function addGlobalStyle(css) {
var head, style;
head = document.getElementsByTagName('head')[0];
if (!head) { return; }
style = document.createElement('style');
style.type = 'text/css';
style.innerHTML = css;
head.appendChild(style);
}
addGlobalStyle('p { font-size: large ! important; }');这个函数只一个字符串参数,包含要插入到页面中的样式规则。它一成不变地把您的样式规则插入到页面 <head> 段的 <style> 元素中。Firefox 自动判别这些变化,解释样式规则,并应用到页面中。您应该把许多不同的样式规则包含到一次函数调用中;只要把连接成一个字符串然后传给函数。
获取元素样式 →