①x=document.getElementById("demo") //查找元素 ②x.innerHTML="Hello JavaScript"; //改变内容

<!DOCTYPE html>
<html>
<body>

<h1>我的第一段 JavaScript</h1>

<p >
JavaScript 能改变 HTML 元素的内容。
</p>

<script>
function myFunction()
{
x=document.getElementById("demo"); // 找到元素
x.innerHTML="Hello JavaScript!"; // 改变内容
}
</script>

<button type="button" onclick="myFunction()">点击这里</button>

</body>
</html>

相关文章:

  • 2021-10-19
  • 2022-01-23
  • 2022-01-23
  • 2021-12-27
  • 2022-12-23
  • 2021-05-30
  • 2021-10-30
  • 2021-12-21
猜你喜欢
  • 2021-06-27
  • 2022-12-23
  • 2021-11-29
  • 2022-12-23
  • 2021-12-13
  • 2021-10-09
  • 2022-12-23
相关资源
相似解决方案