JavaScript DOM 操作CSS

来自:互联网
时间:2020-02-23
阅读:
免费资源网 - https://freexyz.cn/

更改P元素的样式:

<html>
<body>
<p id="p2">Hello World!>
<script>
document.getElementById("p2").style.color = "blue";
</script>
<p>The paragraph above was changed by a script.</p>
</body>
</html>

单击按钮时,此示例更改id="id1"元素的样式:

<!DOCTYPE html>
<html>
<body>
<h1 id="id1">My Heading 1</h1>
<button type="button"
onclick="document.getElementById('id1').style.color = 'red'">
点击我!>
</body>
</html>
免费资源网 - https://freexyz.cn/
返回顶部
顶部