這篇文章主要介紹怎么在JS中改變DOM元素的文本內(nèi)容,文中介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們一定要看完!
成都創(chuàng)新互聯(lián)公司專注于企業(yè)全網(wǎng)營(yíng)銷推廣、網(wǎng)站重做改版、雞西梨樹網(wǎng)站定制設(shè)計(jì)、自適應(yīng)品牌網(wǎng)站建設(shè)、H5技術(shù)、商城網(wǎng)站定制開發(fā)、集團(tuán)公司官網(wǎng)建設(shè)、外貿(mào)網(wǎng)站制作、高端網(wǎng)站制作、響應(yīng)式網(wǎng)頁(yè)設(shè)計(jì)等建站業(yè)務(wù),價(jià)格優(yōu)惠性價(jià)比高,為雞西梨樹等各大城市提供網(wǎng)站開發(fā)制作服務(wù)。
HTML表單內(nèi)容:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> <div class="box"> <p></p> </div> </body> </html>
1.textContent:
<script> const box=document.querySelector(".box"); console.log(box); const p=document.querySelector('p'); console.log(p); //textContent:添加文本 p.textContent ="hello world"; </script>
2.innerText:
<script> const box=document.querySelector(".box"); console.log(box); const p=document.querySelector('p'); console.log(p); p.innerText ="php.cn"; </script>
3.innerHTML:
<script> const box=document.querySelector(".box"); console.log(box); const p=document.querySelector('p'); console.log(p); //將html字符串渲染出來(lái)應(yīng)該使用innerHTML p.innerHTML='<em style="color:red">php.cn</em>'; </script>
以上是“怎么在JS中改變DOM元素的文本內(nèi)容”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對(duì)大家有幫助,更多相關(guān)知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!
當(dāng)前名稱:怎么在JS中改變DOM元素的文本內(nèi)容
本文網(wǎng)址:http://muchs.cn/article30/ghijpo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站建設(shè)、外貿(mào)網(wǎng)站建設(shè)、網(wǎng)站改版、軟件開發(fā)、網(wǎng)站維護(hù)、建站公司
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)