JavaScript实现http地址自动检测并添加URL链接


<textarea id="txt"> 本文地址:http://www.zhangxinxu.com/wordpress/?p=288,您可以访问我的博客首页http://www.zhagxinxu.com/wordpress/查看更多精彩的文章!2010-04-13</textarea> <p><button id="btn">点击转换</button></p> <div id="show"></div>
JS代码:
<script type="text/javascript"> var $ = function(id){ return document.getElementById(id); }; $("btn").onclick = function(){ var v = $("txt").value; var reg = /(http:\/\/|https:\/\/)((\w|=|\?|\.|\/|&|-)+)/g; v = v.replace(reg, "<a href='$1$2'>$1$2</a>").replace(/\n/g, "<br />"); $("show").innerHTML = v; }; </script>


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM