巧用cssText屬性批量操作樣式

2021-09-02 02:25:10 字數 586 閱讀 4046

給乙個html元素設定css屬性:

var d= document.getelementbyid("container");

d.style.height="7px";

d.style.weight="17px";

和innerhtml一樣,csstext很快捷且所有瀏覽器都支援。

一組樣式屬性及其值的文字表示。將文字格式化為乙個 css 樣式表,去掉了包圍屬性和值的元素選擇器的花括號。

*但會覆蓋之前的樣式,應該採用疊加的方式以保留原有的樣式。

document.getelementbyid('inp1').style.csstext;  //獲取input標籤的樣式"width: 220px; height: 20px;"

//設定標籤樣式

function getstyle()

function setstyle(el, strcss)

[url]

巧用cssText屬性批量操作樣式

給乙個html元素設定css屬性,如12 34varhead document.getelementbyid head head.style.width 200px head.style.height 70px head.style.display block 這樣寫太羅嗦了,為了簡單些寫個工具函式...

JS 巧用cssText屬性 操作樣式

給乙個html元素設定css屬性,傳統做法 varmybox document.getelementbyid mybox mybox.style.width 200px mybox.style.height 70px mybox.style.display block 這樣寫很煩,尤其是很多的時候,...

css text文字屬性(三)

1.text decoration屬性 作用 設定文字修飾線。取值 text decoration line 不支援 指定文字裝飾的種類。相當於 css1 時的text decoration屬性 text decoration style 不支援 指定文字裝飾的樣式。text decoration ...