在特殊字符Jquery之后换行字符串

时间:2018-03-05 14:42:38

标签: jquery

我的HTML文档中有这个字符串:

<dd class="wp-caption-text gallery-caption" id="gallery-2-3976">
An awesomephoto © goodjobstudio</dd>

在Jquery中,我想要包含字符串的这一部分:© goodjobstudio

所以我在Jquery中尝试这个:

str = $('.slider-for .gallery-item .wp-caption-text').text();
str.replace(/(©)+/gi, '<span>$1</span>');

但它不起作用

感谢您的帮助!

2 个答案:

答案 0 :(得分:1)

使用substring应该更快更容易。

&#13;
&#13;
let str = "An awesomephoto © goodjobstudio"
str = str.substring(0, str.indexOf('©')).trim();
console.log(str);
&#13;
&#13;
&#13;

答案 1 :(得分:0)

我认为以下内容应该:

let str = $('.wp-caption-text').html();
$('.wp-caption-text').html(str.replace(/(©)+/gi, '<span>$1</span>'));
console.log($('.wp-caption-text').html());