<!-- 改变 HTML 样式
如需改变 HTML 元素的样式,请使用这个语法:
document.getElementById(id).style.property=新样式 -->
<p id="p1">Hello world!</p>
<P id="p2">Hello world!</P>
<script>
document.getElementById("p2").style.color = "blue";
document.getElementById("p2").style.fontFamily = "Arial";
document.getElementById("p2").style.fontSize = "larger";
</script>
<p>以上段落通过脚本修改。</p>
<!-- 使用事件
HTML DOM 允许我们通过触发事件来执行代码。
比如以下事件:
元素被点击。
页面加载完成。
输入框被修改。
…… -->
<h1 id="id1">我的标题</h1>
<button type="button" οnclick="document.getElementById('id1').style.color = 'red'"></button>