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 id="mytest">

 

  <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 id="mytest">

 

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

</div>

posted on 2015-06-08 16:49  幸福之家128817  阅读(3142)  评论(0编辑  收藏  举报