我有以下代码:
var code = '<span class="category-str-list">
<a href="link1.html">Spas</a>,<a href="link2.html">Massage</a></span>';
如何获得以下字符串?
var activities = 'Spas, Massage';
答案 0 :(得分:3)
只需将其解析为HTML并获取文本内容?
var activities = $(code).text();
var code = '<span class="category-str-list"><a href="link1.html">Spas</a>,<a href="link2.html">Massage</a></span>';
var activities = $(code).text();
$('body').html(activities)
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
&#13;