javascript写入
写入HTML元素 (Writing into an HTML element)
To write string/text into an HTML element, we use the following things:
要将字符串/文本写入HTML元素,我们使用以下内容:
- There must be an HTML element like paragraph, span, div etc. - 必须有一个HTML元素,例如段落,跨度,div等。 
- An HTML element must have an Id. - HTML元素必须具有ID。 
- We access the HTML element by using the id (to access an HTML element using Id, we use an HTML DOM method getElementbyId()). - 我们使用id访问HTML元素(要使用Id访问HTML元素,我们使用HTML DOM方法getElementbyId() )。 
- Then, we write the text to the HTML element by using an HTML DOM property innerHTML. - 然后,我们使用HTML DOM属性innerHTML将文本写入HTML元素。 
Example:
例:
In this example, we have two paragraphs with p1 and p2 ids, we are writing two different texts in these HTML elements (paragraphs).
在此示例中,我们有两个具有p1和p2 id的段落,我们在这些HTML元素(段落)中编写了两个不同的文本。
Example:
例:
<html>
<head>
<title>JavaScipt Example</title>
</head>
<body>
<p id="p1"></p>
<p id="p2"></p>
<script>
document.getElementById("p1").innerHTML = "Hello world!";
document.getElementById("p2").innerHTML = 10+20;
</script>
</body>
</html>
Output
输出量
Hello world!
30
翻译自: https://www.includehelp.com/code-snippets/write-into-an-HTML-element-in-javascript.aspx
javascript写入