JQuery:在关闭的标签之间选择文本 [英] JQuery: Select text between closed tags
本文介绍了JQuery:在关闭的标签之间选择文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
已提出类似问题,但不够相似。
有这种结构:
< p class =text>
< b> 1< / b>这是第一个< b> 2< / b>这是第二个< b> 3< / b&
< / p>
如何选择已关闭标签之间的文本?即这是第一点。
内容通过JSON调用反馈,所以我不能对他们给我的结构做太多。 p>
感谢!
解决方案
可取代 ; b>#< / b>
到更容易分割的结果,然后迭代结果
jQuery:
var points = $('。text').html()。replace(/< b>。< \ / b> / g,',') .split(','),
$ results = $('#results');
for(var i in points){
if($ .trim(points [i]),length> 0){
$ results.html($ results.html points [i] +< br />);
}
}
Similar questions have been asked but not quite similar enough!
Given this structure:
<p class="text">
<b>1</b>this is point one<b>2</b>this is point two<b>3</b>
</p>
How would I select the text between the closed tags? ie "this is point one".
The content is fed back via a JSON call so I can't do much with the structure they're giving me.
Thanks!
解决方案
can replace your <b>#</b>
to something easier to split on then iterate over the results
jQuery:
var points = $('.text').html().replace(/<b>.<\/b>/g, ',').split(','),
$results = $('#results');
for (var i in points) {
if ($.trim(points[i]).length > 0) {
$results.html($results.html() + points[i] + "<br />");
}
}
这篇关于JQuery:在关闭的标签之间选择文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文