-1

我有下面的代码来获取按钮单击的日期和时间。我想以不同的颜色获得输出..需要哪些更改?

<!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> 
4

1 回答 1

1

尝试使用这里object.style.color的文档,所以在你的情况下

<!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> 
于 2013-01-29T04:53:43.693 回答