如何在JavaScript中使用outerHTML? [英] How to use outerHTML in JavaScript?

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

问题描述

如何在JavaScript中使用outerHTML?谢谢

How to use outerHTML in JavaScript? Thanks

推荐答案

outerHTML是元素的HTML,包括元素本身。将其与元素的innerHTML进行对比,元素是元素开始和结束标记中包含的HTML。根据定义,没有开始和结束标记的元素都没有innerHTML。

The outerHTML is the HTML of an element including the element itself. Contrast this with the innerHTML of the element, which is the HTML contained within an elements opening and closing tags. By definition, elements without both opening and closing tags do not have innerHTML.

当你想要完全替换元素及其内容时,请使用outerHTML。当您只想替换元素的内容时,请使用innerHTML。

Use the outerHTML when you want to completely replace an element and its contents. Use innerHTML when you only want to replace the contents of the element.

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

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