Style cssText 屬性

定義和用法
cssText 屬性設置或返回作為字串的樣式聲明的內容。
語法
設置 cssText 屬性:
Object.style.cssText="string"
返回 cssText 屬性:
Object.style.cssText
值 | 描述 |
---|---|
string | 規定樣式聲明的內容。 |
流覽器支持
所有主要流覽器都支持 cssText 屬性。
實例
實例
獲取作為字串的樣式聲明:
<html>
<head>
<script>
function displayResult()
{
alert(document.getElementById("p1").style.cssText);
}
</script>
</head>
<body>
<p id="p1" style="border:2px dashed green;color:red;">This is a paragraph.</p>
<br>
<button type="button" onclick="displayResult()">Get style declaration</button>
</body>
</html>
<head>
<script>
function displayResult()
{
alert(document.getElementById("p1").style.cssText);
}
</script>
</head>
<body>
<p id="p1" style="border:2px dashed green;color:red;">This is a paragraph.</p>
<br>
<button type="button" onclick="displayResult()">Get style declaration</button>
</body>
</html>
