如何使用innerHTML附加到对象 [英] how to append to a object with innerHTML

查看:145
本文介绍了如何使用innerHTML附加到对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法用.innerHTML向DOM对象添加信息而不替换那里存在的东西?

Is there a way to add information to a DOM object with .innerHTML without replacing what exists there?

例如: document.getElementById ('div')。innerHTML ='stuff';

将返回< div id =div > stuff< / div>

然后进行类似的调用: document.getElementById('div')。 innerHTML ='和things';

And then a similar call: document.getElementById('div').innerHTML = ' and things';

将div设置为< div id =div>东西和东西< / div>

推荐答案

document.getElementById('mydiv').innerHTML = 'stuff'
document.getElementById('mydiv').innerHTML += 'and things'
document.getElementById('mydiv').innerHTML += 'and even more'

这篇关于如何使用innerHTML附加到对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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