javascript
javascript写入_如何在JavaScript中写入HTML元素?
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寫入
總結
以上是生活随笔為你收集整理的javascript写入_如何在JavaScript中写入HTML元素?的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 合肥治疗子宫发育不良最好的医院推荐
- 下一篇: 颐和园儿童没有身份证能进吗