2
我想用我的HTMLCollection剝離出來,它包含,例如元素的標籤,給出的HTML:修改的HTMLCollection返回所有的innerHTML
<p><span>Hello, <i>world!</i></span> Some more text</p>
我想回
<p>Hello, <i>world!</i> Some more text</p>
當我在我的html中搜索span標記時返回一個HTMLCollection,這似乎是我獲得所有span標記的最簡單方法,我該如何使用這個集合來完全去除標記並保留所有innerhtml ?
$scope.modifyHtml = function (html) {
var el = document.createElement('div');
el.innerHTML = html;
var spans = el.getElementsByTagName('span');
//Remove these spans from el but keep their inner!
return el.innerHTML;
}
'$('p')。find('span')。contents()。unwrap();'將解包任何跨度內容 –
@ A.Wolff - 聽起來像答案? – adeneo
@adeneo我不知道,這聽起來像OP是使用angularJS,不知道他使用的是jQuery(不是jqLite) –