运行结果尺寸: 300 x 150
x
 
<!DOCTYPE html>
<html>
<body>
<p>这是一个 p 元素</p>
<p>这也是一个 p 元素。</p>
<p>这也是一个 p 元素 - 单击该按钮可更改此文档中所有 p 元素的背景颜色。</p>
<button onclick="myFunction()">试一试</button>
<script>
function myFunction() {
  var x = document.getElementsByTagName("P");
  var i;
  for (i = 0; i < x.length; i++) {
    x[i].style.backgroundColor = "red";
  }
}
</script>
</body>
</html>
×

报个问题: