高分问题?如何给图片自动加链接。求助!!!
我的文章系统里有图片,我如何在前台读取文章时,把文章内容里的每副图前加一个链接如:
<a href= "pic/upload001.gif " target= "_blank "> <img src= "pic/upload001.gif " width= "90 " hight= "60 "> </a>
第二是要判断 图片在文章录入时就有链接,就不加链接
请各位大侠指点迷津!!!
------解决方案-------------------- <script>
function test(str){
var str=textarea1.value;
re=/( <img\s*src=\ "(.*?)\ "[^> ]*> )(?! <\/a> )/ig;
str=str.replace(re, " <a href=\ "$2\ " target=\ "_blank\ "> $1 </a> ");
document.write(str);}
</script>
<body onload= "test() " >
<textarea id=textarea1>
我的文章系统里有图片,我如何在前台读取文章时,把文章内容里的每副图前加一个链接如:
<a href= "pic/upload001.gif " target= "_blank "> <img src= "pic/upload001.gif " width= "90 " hight= "60 "> </a>
第二是要判断 图片在文章录入时就有链接,就不加链接
请各位大侠指点迷津!!!
<img src= "pic/upload001.gif " width= "90 " hight= "60 ">
</textarea>
</body>
大致的思路,你参考一下吧
------解决方案--------------------function imglink()
{
var imgs = document.getElementById( "fontzoom ").getElementsByTagName( "img ");
for(var i=0;i <imgs.length;i++)
{
imgs.style.cursor= "hand ";
imgs[i].onclick = function(){window.open(this.src);}
}
}
这个没外框