如何使用span标签拆分包含逗号的字符串 [英] How to split string containing comma using span tag
本文介绍了如何使用span标签拆分包含逗号的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有一个包含以逗号分隔的标签的字符串:
There is a string containing tags separated by comma:
<div class="article" id="1">
<span class="tags">Dog, Cat, Bird, Pig</span>
</div>
<div class="article" id="2">
<span class="tags">Asia, Africa, Australia, Europe</span>
</div>
....
$ b $ p
我想在标签中使用span标签
I would like to wrap each item using span tag within the tags class so that each of them can be individually styled like this
<span class="tags"><span>Dog</span><span>Cat<span>...</span>
推荐答案
$('.tags').html($('.tags').html().split(', ').map(function(el) {return '<span>' + el + '</span>'}))
< rel =nofollow>此处
这篇关于如何使用span标签拆分包含逗号的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文