如何将html元素变成字符串
有一段html
<style>div {
color: red;
}
</style>
<div>
hello world
</div>
想要在 js 中获取到一个字符串<style>....</style>
类似console.log(document.querySelector('style'))
在浏览器打印出的效果
使用es6的模板字符串`` (一对反单引号) 将内容包裹起来。
然后变量赋值给它就可以了。
let str = `任意字符串`
使用模板字符串,键盘左上波浪线下
回答
以上是 如何将html元素变成字符串 的全部内容, 来源链接: www.h5w3.com/112787.html