我的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>');
但它不起作用
感谢您的帮助!
答案 0 :(得分:1)
使用substring
应该更快更容易。
let str = "An awesomephoto © goodjobstudio"
str = str.substring(0, str.indexOf('©')).trim();
console.log(str);
&#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());