我试图让每一个文字在我的html
数据由用户输入如何提取从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
最后像
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');
如何做到这一点的阵列?谢谢您的帮助!
是如何数组元素应该被分开。在这个例子中,它说数组应该有一个元素。那么为什么不使用字符串作为累加器而不是数组。 –