TUTORIAL前端与浏览器FETCHED
Style cssText 属性
Style cssText 属性 Style 对象 定义和用法 cssText 属性设置或返回作为字符串的样式声明的内容。 语法 设置 cssText 属性: Object.style.cssText='string' 返回 cssText 属性: Object.style.cssText 值 描述 string 规定样式声明的内容。 浏览器支持 所有主要浏览器都支持 c..
更新于 2026/7/16
教程详情页默认 noindex。
Style cssText 属性
Style 对象
定义和用法
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>
尝试一下 »
Style 对象