js提取文本内容中的网址url并自动加上超链接地址

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_38543537/article/details/84562209
<div class="thread_mess" id="thread_imgid" data-tid="67902">
     <div class="message">点击跳转到百度首页:https://www.baidu.com/</div>    
</div>
//链接可点击
    if($('.thread_mess').length){
        var textR=$('.thread_mess').html();
        var reg = /(http:\/\/|https:\/\/)((\w|=|\?|\.|\/|&|-)+)/g;
        var imgSRC=$('.thread_mess img').attr('src');
        if(reg.exec(imgSRC)){
            return false
        }else{
          textR = textR.replace(reg, "<a href='$1$2'>$1$2</a>");
        }
        document.getElementById('thread_imgid').innerHTML = textR;
    }

文章来自:https://www.cnblogs.com/chenguiya/p/5221196.html

猜你喜欢

转载自blog.csdn.net/qq_38543537/article/details/84562209