JQuery代码:

var regexp = /((http|ftp|https|file):\/\/([\w\-]+\.)+[\w\-]+(\/[\w\u4e00-\u9fa5\-\.\/?\@\%\!\&=\+\~\:\#\;\,]*)?)/ig;
        var url = $('#mytest').html();
        var thisurl = url.match(regexp);
        console.info(thisurl);

 

html代码:

<div >

 

  <img src="http://img.weibo.com/aa.jpg">

</div>

 

 

地址替换成链接:

var regexp = /((http|ftp|https|file):\/\/([\w\-]+\.)+[\w\-]+(\/[\w\u4e00-\u9fa5\-\.\/?\@\%\!\&=\+\~\:\#\;\,]*)?)/ig;
        var url = $('#mytest').html();
        document.write(replaceReg(regexp,url));

function replaceReg(reg,str){
        return str.replace(reg,function(m){return '<a href="'+m+'">'+m+'</a>';})
    }

 

 

<div >

 

  你是我的小丫小苹果怎么爱你都不嫌多。。。。百度去吧http>//www.baidu.com错误那么多。。。。

</div>

相关文章:

  • 2022-12-23
  • 2022-01-18
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-14
  • 2021-11-14
  • 2021-12-20
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-10-05
  • 2022-01-08
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案