我有用于获取按钮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>
答案 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>