HTML DOM Style color attribute
Definition and Usage
color property sets or returns the color of the text.
grammar
Setting color properties:
Object.style.color="color|inherit"
Returns color attributes:
Object.style.color
值 | 描述 |
---|---|
color | 规定文本的颜色。在 CSS 颜色值 中寻找可能的颜色值的完整列表。 |
inherit | color 属性的值从父元素继承。 |
Browser Support
All major browsers support color attributes.
Note: IE7 and earlier versions do not support the "inherit" value.IE8 only provides! DOCTYPE supported "inherit". IE9 support "inherit".
Examples
Examples
Change the color of the text:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>本教程(w3big.com)</title>
<script>
function displayResult(){
document.getElementById("p1").style.color="#ff0000";
document.getElementById("p2").style.color="magenta";
}
</script>
</head>
<body>
<p id="p1">这是一个示例段落。</p>
<p id="p2">这也是一个示例段落。</p>
<br>
<input type="button" onclick="displayResult()" value="修改文本颜色">
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>本教程(w3big.com)</title>
<script>
function displayResult(){
document.getElementById("p1").style.color="#ff0000";
document.getElementById("p2").style.color="magenta";
}
</script>
</head>
<body>
<p id="p1">这是一个示例段落。</p>
<p id="p2">这也是一个示例段落。</p>
<br>
<input type="button" onclick="displayResult()" value="修改文本颜色">
</body>
</html>
try it"
Style Objects