在javascript中更改日期函数输出的颜色

时间:2013-01-29 04:45:05

标签: javascript

我有用于获取按钮click.i的日期和时间的波纹管代码。我想以不同的颜色获得输出...需要进行哪些更改?

<!DOCTYPE html>
<html>
<head>
<script>
function displayDate()
{
document.getElementById("demo").innerHTML=Date();
}
</script>
</head>
<body>

<h1>My First JavaScript</h1>
<p id="demo">click on the button bellow.....</p>

<button type="button" onclick="displayDate()">Display Date</button>

</body>
</html> 

1 个答案:

答案 0 :(得分:1)

尝试使用object.style.color文档here,因此在您的情况下

<!DOCTYPE html>
<html>
<head>
<script>
function displayDate()
{
document.getElementById("demo").innerHTML=Date();
document.getElementById("demo").style.color = "red";
}
</script>
</head>
<body>

<h1>My First JavaScript</h1>
<p id="demo">click on the button bellow.....</p>

<button type="button" onclick="displayDate()">Display Date</button>

</body>
</html>