我正在尝试获取用户输入的html
数据中的每个文本
我有以下这样的html
<em>first part</em> of texts here
<table>
......
......
</table>
<em>second part</em> of texts
我使用jQuery。
project =[];
$(htmlData).contents().each(function(){
if($(this).is('table')){
//do something with table
}else{
if(this.nodeType === 3) { // Will only select element nodes
project.push($(this).text());
}else if(this.nodeType === 1){
project.push(this.outerHTML);
}
}
}
数组最终形成如下所示。
array(0=>'<em>first part</em>', 2=>'of texts here',3=>'<em>second part</em>',4=>'of texts')
我希望能够获得以下形式的数组:
array(0=>'<em>first part</em>of texts here',1=>'<em>second part</em>of texts');
如何实现这个?感谢您的帮助!