Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何将html标记存储到数组中_Javascript_Jquery - Fatal编程技术网

Javascript 如何将html标记存储到数组中

Javascript 如何将html标记存储到数组中,javascript,jquery,Javascript,Jquery,我在上一篇文章中有一个问题 我想将每个节点存储为完整html标记 数据数组应该是 ['<em>test</em>', 'here for the testing purpose', 'second line', '<strong>texts</strong>', 'here'] 但它只是一个商店 ['test', 'here for the testing purpose','texts','here'] 是否也可以存储html标记 非常感

我在上一篇文章中有一个问题

我想将每个
节点
存储为
完整html标记

数据
数组应该是

['<em>test</em>', 'here for the testing purpose',
'second line', '<strong>texts</strong>', 'here']
但它只是一个商店

['test', 'here for the testing purpose','texts','here'] 
是否也可以存储html
标记

非常感谢

返回包含元素外部标记的标记:

data.push(this.outerHTML);
替换

data.push($(this).html());

记得吗

--DOM对象

<代码>$(此)--jQuery对象


尽可能尝试使用
DOM
对象而不是
jQuery
对象,因为前者速度稍快,因为它消除了将它们转换为后者然后应用方法的额外开销。。应该不是什么大问题,只是为了获取信息。

js中的数组是
[…]
而不是
(…)
data.push($(this).html());
data.push(this.outerHTML);