我試圖讓每一個文字在我的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');
如何做到這一點的陣列?謝謝您的幫助!
是如何數組元素應該被分開。在這個例子中,它說數組應該有一個元素。那麼爲什麼不使用字符串作爲累加器而不是數組。 –