$(this).html($(this).html().replace( /#([a-zA-Z0-9]+)/g,'<a class="hashtag" href="' + SP_source() + '?hashtag=$1">#$1</a>'
我已经尝试了上面的它正在替换所有散列,包括在我需要帮助替换所有散列而不替换颜色代码的样式中
当前结果:
#808000;">fvfvfvfvfvfvfvf
预期成绩; fvfvfvfvfvfvfvf
(带有应用颜色)
代码:
<p>
<span style="color: <a class=" hashtag"="" href="http://owos.lan/?hashtag=808000">
#808000;">
<em><strong>fvfvfvfvfvfvfvf #trends #trend2</strong></em>
</span>
</p>
html代码:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<p><span style="font-size: 18pt;">svzvzgv #trends #trends2</span></p>
</body>
</html>
js中的代码
$('.text-wrapper').each(function () {
$(this).html($(this).html().replace( /#([a-zA-Z0-9]+)/g,'<a class="hashtag" href="' + SP_source() + '?hashtag=$1">#$1</a>'
));
});
您可以尝试使用负面展望。
$(this).html($(this).html().replace( /#([a-fA-F0-9]{6}|[a-fA-F0-9]{3})(?![a-zA-Z0-9]+)/g, '<a class="hashtag" href="' + SP_source() + '?hashtag=$1">#$1</a>')
这也应该处理您的 3 个字符的短颜色代码。如果您只想保留 6 个字符代码,请使用此
$(this).html($(this).html().replace( /#([a-fA-F0-9]{6})(?![a-zA-Z0-9]+)/g, '<a class="hashtag" href="' + SP_source() + '?hashtag=$1">#$1</a>')
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句