如何使用JS向HTML正文添加内容? [英] How to add content to html body using JS?

查看:93
本文介绍了如何使用JS向HTML正文添加内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的html <body>中有很多<section>,并希望通过javascript添加更多内容.但是,使用innerHTML只是将我现有的部分替换为新的部分,而不是将其添加到旧的部分中.

I have many <section> in my html <body> and want to add more through javascript. However, using innerHTML is just replacing my existing sections with new ones, instead of adding them to the old ones.

我还能使用什么?

推荐答案

您可以使用

document.getElementById("parentID").appendChild(/*..your content created using DOM methods..*/)

document.getElementById("parentID").innerHTML+= "new content"

这篇关于如何使用JS向HTML正文添加内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆