我有一个字符串,我想从它获得文本:
var text = "<p>This is awesome and</p> <p>some random</p> and <custom>complex boring text</custom> <p>I</p> <custom>really need to clean</custom> up my room. that feel"我想从数组中的所有<custom />标记中获取文本。我正试图得到这样的结果:
['complex boring text', 'really need to clean']我该怎么做?
发布于 2016-03-04 09:08:03
首先是never ever use RegEx to parse HTML。要实现这一点,您可以从jQuery创建一个text对象,然后在使用map()创建文本数组之前先将custom元素去掉。试试这个:
var arr = $(text).filter('custom').map(function() {
return $(this).text();
}).get();
console.log(arr);https://stackoverflow.com/questions/35791919
复制相似问题