JavaScript DOM对象 Write()方法

JavaScript Write()方法用于写入HTML到期或者文档上的任何消息。
换句话说,我们可以说Write()方法用于在文档上显示任何类型的输出或者消息。

语法

document.write()

JavaScript DOM对象 Write()方法示例

<html>
<head>
  <script type="text/javascript">

	  function myfun() {
		  document.write("Hello ONITROAD");
	  }
  </script>

</head>
<body >
  <button onclick="myfun()">按钮</button>

</body>
</html>

插入html元素:

<html>
<head>
  <script type="text/javascript">

	  function myfun() {
		  document.write("<h2>Hello ONITROAD</h2>");
	  }
  </script>

</head>
<body>
  <button onclick="myfun()">
	  click me</button>

</body>
</html>
如何在JavaScript中使用DOM对象Write方法
日期:2020-04-18 01:09:21 来源:oir作者:oir