上问写错了替换后干净的代码: 
<IMG src="http://img.qihoo.com/qhimg/kkk.gif" > 

解决方案 »

  1.   


    <script language="javascript"> 
    str = '<A href="http://rd.union.qihoo.com/ target=_blank><IMG height=50 alt="" src="http://img.qihoo.com/qhimg/kkk.gif" width=70 border=0 onload="javascript:if(this.width>120)this.width=120;if(this.height>120)this.height=120;"></A>'
    str = str.replace(/.*?<img(.*?)src=\"(.*?)\"(.*?)>(.*?)$/i,"<img src=\"$2\">")
    alert(str);
    </script>
      

  2.   

    回上楼,
    如果内容变成这样,就失效了
    <A href="http://rd.union.qihoo.com/stat.html?go=http%3A%2F%2Fwww.100bj.cn%2Fzt%2FMAXBreast%2Findex.aspx&amp;m=183379&amp;p=2001&amp;a=2039&amp;b=1003&amp;oid=865798593&amp;t=1204978972&amp;e=5375debee73a5972af40b3daa0e761d1&amp;r=http%3A%2F%2F192.168.1.5%2F2008bt%2FTopicShow.asp%3FThreadID%3D5627&amp;refid=" target=_blank><IMG height=50 alt="" src="http://img.qihoo.com/qhimg/bbs_img/70_50/1/419/576/851cb2.gif" width=70 border=0></A>不能替换成这样的干净代码
    <IMG src="http://img.qihoo.com/qhimg/bbs_img/70_50/1/419/576/851cb2.gif">
      

  3.   

    <script language="javascript">   
    str = '<A href="http://rd.union.qihoo.com/stat.html?go=http%3A%2F%2Fwww.100bj.cn%2Fzt%2FMAXBreast%2Findex.aspx&amp;m=183379&amp;p=2001&amp;a=2039&amp;b=1003&amp;oid=865798593&amp;t=1204978972&amp;e=5375debee73a5972af40b3daa0e761d1&amp;r=http%3A%2F%2F192.168.1.5%2F2008bt%2FTopicShow.asp%3FThreadID%3D5627&amp;refid=" target=_blank><IMG height=50 alt="" src="http://img.qihoo.com/qhimg/bbs_img/70_50/1/419/576/851cb2.gif" width=70 border=0></A>' 
    //str = str.replace(/.*?<img(.*?)src=\"(.*?)\"(.*?)>(.*?)$/i," <img src=\"$2\"> ") 
    str = str.replace(/.*?<img(.*?)src=\"(.*?)\"(.*?)>(.*?)$/i," <img src=\"$2\"> ") 
    alert(str); 
    </script> 
      

  4.   

    你以上写法是对的,
    但这样加个表单就不行了!
    帮忙看一下!
    <script>
    function Replace()
    {
      var ta=document.getElementById("ta");
      ta.value= ta.value.replace(/.*?<img(.*?)src=\"(.*?)\"(.*?)> (.*?)$/i,"  <img src=\"$2\">") 
    }
    </script>
    <body> 
    <textarea style="width:400px;height:120px" id="ta">
    <A href="http://rd.union.qihoo.com/stat.html?go=http%3A%2F%2Fwww.100bj.cn%2Fzt%2FMAXBreast%2Findex.aspx&amp;m=183379&amp;p=2001&amp;a=2039&amp;b=1003&amp;oid=681805886&amp;t=1204983753&amp;e=811982a72ccc201f284573bed4a07945&amp;r=http%3A%2F%2F192.168.1.5%2F2008bt%2FTopicShow.asp%3FThreadID%3D5627&amp;refid=" target=_blank><IMG height=50 alt="" src="http://img.qihoo.com/qhimg/bbs_img/70_50/1/419/576/851cb2.gif" width=70 border=0></A>
    </textarea><br/>
    <input type='button' value='提交' onclick='Replace()'/>
      

  5.   

    先获取图片地址,然后再重新拼接成<img src="图片地址"/>,这样应该更方便一些获取图片地址的正则:(src\s*=\s*)([\s\S]+?)(\""|\')
      

  6.   

    <script>
    function Replace()
    {
      var ta=document.getElementById("ta");
      ta.value= ta.value.replace(/<a[^>]*?>(?:(?!<img|<\/a)[\s\S])*<img[^>]*?src=["']?([^"'>]*)["']?(?:(?!<\/a)[\s\S])*<\/a>/ig,"<img src='$1' />");
    }
    </script>
    <body> 
    <textarea style="width:400px;height:120px" id="ta">
    <A href="http://rd.union.qihoo.com/stat.html?go=http%3A%2F%2Fwww.100bj.cn%2Fzt%2FMAXBreast%2Findex.aspx&amp;m=183379&amp;p=2001&amp;a=2039&amp;b=1003&amp;oid=681805886&amp;t=1204983753&amp;e=811982a72ccc201f284573bed4a07945&amp;r=http%3A%2F%2F192.168.1.5%2F2008bt%2FTopicShow.asp%3FThreadID%3D5627&amp;refid=" target=_blank><IMG height=50 alt="" src="http://img.qihoo.com/qhimg/bbs_img/70_50/1/419/576/851cb2.gif" width=70 border=0></A>
    </textarea><br/>
    <input type='button' value='提交' onclick='Replace()'/>
      

  7.   

    加个\s 精细点...
    ta.value= ta.value.replace(/<a[^>]*?>(?:(?!<img|<\/a)[\s\S])*<img[^>]*?src=["']?([^"'>\s]*)["']?(?:(?!<\/a)[\s\S])*<\/a>/ig,"<img src='$1' />");
      

  8.   

    问题在你把代码从这里拷贝出去后,要删除其中csdn给增加的空格,否则就不正确了。
    str = str.replace(/.*?<img(.*?)src=\"(.*?)\"(.*?)>(.*?)$/i,"<img src=\"$2\">")
    我再发看看还给加空格不。
      

  9.   

    为什么我发的系统会在两个<>括号两边给我多加空格呢,上面所有的都是,我就纳闷了。
      

  10.   

    回10楼,he_8134 
    你的代码如果不输入带超链接的内容,就失效了
    不能去除width="60" height="40"
    <script>
    function Replace()
    {
      var ta=document.getElementById("ta");
      ta.value= ta.value.replace(/<a[^>]*?>(?:(?!<img|<\/a)[\s\S])*<img[^>]*?src=["']?([^"'>]*)["']?(?:(?!<\/a)[\s\S])*<\/a>/ig,"<img src='$1' />");
    }
    </script>
    <body> 
    <textarea style="width:400px;height:120px" id="ta">
    <img src='http://img.qihoo.com/qhimg/bbs_img/70_50/1/419/576/851cb2.gif' width="60" height="40" /></textarea><br/>
    <input type='button' value='提交' onclick='Replace()'/>
      

  11.   

    回myvicy,我已经删除所有空格,还是失效
    请用插入源代码的方式,再贴一次看看?
      

  12.   


    <script language="javascript">   
    str = '<A href="http://rd.union.qihoo.com/stat.html?go=http%3A%2F%2Fwww.100bj.cn%2Fzt%2FMAXBreast%2Findex.aspx&amp;m=183379&amp;p=2001&amp;a=2039&amp;b=1003&amp;oid=865798593&amp;t=1204978972&amp;e=5375debee73a5972af40b3daa0e761d1&amp;r=http%3A%2F%2F192.168.1.5%2F2008bt%2FTopicShow.asp%3FThreadID%3D5627&amp;refid=" target=_blank><IMG height=50 alt="" src="http://img.qihoo.com/qhimg/bbs_img/70_50/1/419/576/851cb2.gif" width=70 border=0></A>' 
    //str = str.replace(/.*?<img(.*?)src=\"(.*?)\"(.*?)>(.*?)$/i," <img src=\"$2\"> ") 
    str = str.replace(/.*?<img(.*?)src=\"(.*?)\"(.*?)>(.*?)$/i,"<img src=\"$2\">") 
    alert(str); 
    </script> 本地测试没有问题。
      

  13.   

    myvicy 我知道这样没问题,但是你写个表单试一试?就发现问题了。
      

  14.   

    下面是我测试过没有问题的代码,环境2003+ie 6.0
    <script>
    function Replace()
    {
      var ta=document.getElementById("ta");
      ta.value= ta.value.replace(/.*?<img(.*?)src=\"(.*?)\"(.*?)>(.*?)$/i,"<img src=\"$2\">");
    }
    </script>
    <body> 
    <textarea style="width:400px;height:120px" id="ta"><A href="http://rd.union.qihoo.com/stat.html?go=http%3A%2F%2Fwww.100bj.cn%2Fzt%2FMAXBreast%2Findex.aspx&amp;m=183379&amp;p=2001&amp;a=2039&amp;b=1003&amp;oid=865798593&amp;t=1204978972&amp;e=5375debee73a5972af40b3daa0e761d1&amp;r=http%3A%2F%2F192.168.1.5%2F2008bt%2FTopicShow.asp%3FThreadID%3D5627&amp;refid=" target=_blank><IMG height=50 alt="" src="http://img.qihoo.com/qhimg/bbs_img/70_50/1/419/576/851cb2.gif" width=70 border=0></A></textarea><br/>
    <input type='button' value='提交' onclick='Replace()'/>
      

  15.   

    哈哈哈,非常感谢myvicy,你这次贴的代码没有问题了
    30分是你的了。马上结
      

  16.   

    等等,还是有个可怕的问题!插入多张图片后,最后只乘一张了
    <script>
    function Replace()
    {
      var ta=document.getElementById("ta");
      ta.value= ta.value.replace(/.*?<img(.*?)src=\"(.*?)\"(.*?)>(.*?)$/i,"<img src=\"$2\">");
    }
    </script>
    <body> 
    <textarea style="width:400px;height:120px" id="ta"><P><A href="http://rd.union.qihoo.com/stat.html?go=http%3A%2F%2Fwww.100bj.cn%2Fzt%2FFetal%2Findex.aspx&amp;m=183379&amp;p=2001&amp;a=2039&amp;b=1003&amp;oid=1576142391&amp;t=1205063728&amp;e=955751a7f884268a5ab158f592a8a7c9&amp;r=http%3A%2F%2F192.168.1.5%2F2008bt%2FTopicShow.asp%3FThreadID%3D5627&amp;refid=" target=_blank><IMG height=50 alt="" src="http://img.qihoo.com/qhimg/bbs_img/70_50/1/419/575/dfa4f9.gif" width=70 border=0></A><A href="http://rd.union.qihoo.com/stat.html?go=http%3A%2F%2Fwww.100bj.cn%2Fzt%2FFetal%2Findex.aspx&amp;m=183379&amp;p=2001&amp;a=2039&amp;b=1003&amp;oid=1576142391&amp;t=1205063728&amp;e=955751a7f884268a5ab158f592a8a7c9&amp;r=http%3A%2F%2F192.168.1.5%2F2008bt%2FTopicShow.asp%3FThreadID%3D5627&amp;refid=" target=_blank><IMG height=50 alt="" src="http://img.qihoo.com/qhimg/bbs_img/70_50/1/419/575/dfa4f9.gif" width=70 border=0></A><A href="http://rd.union.qihoo.com/stat.html?go=http%3A%2F%2Fwww.100bj.cn%2Fzt%2FFetal%2Findex.aspx&amp;m=183379&amp;p=2001&amp;a=2039&amp;b=1003&amp;oid=1576142391&amp;t=1205063728&amp;e=955751a7f884268a5ab158f592a8a7c9&amp;r=http%3A%2F%2F192.168.1.5%2F2008bt%2FTopicShow.asp%3FThreadID%3D5627&amp;refid=" target=_blank><IMG height=50 alt="" src="http://img.qihoo.com/qhimg/bbs_img/70_50/1/419/575/dfa4f9.gif" width=70 border=0></A><A href="http://rd.union.qihoo.com/stat.html?go=http%3A%2F%2Fwww.100bj.cn%2Fzt%2FFetal%2Findex.aspx&amp;m=183379&amp;p=2001&amp;a=2039&amp;b=1003&amp;oid=1576142391&amp;t=1205063728&amp;e=955751a7f884268a5ab158f592a8a7c9&amp;r=http%3A%2F%2F192.168.1.5%2F2008bt%2FTopicShow.asp%3FThreadID%3D5627&amp;refid=" target=_blank><IMG height=50 alt="" src="http://img.qihoo.com/qhimg/bbs_img/70_50/1/419/575/dfa4f9.gif" width=70 border=0></A><A href="http://rd.union.qihoo.com/stat.html?go=http%3A%2F%2Fwww.100bj.cn%2Fzt%2FFetal%2Findex.aspx&amp;m=183379&amp;p=2001&amp;a=2039&amp;b=1003&amp;oid=1576142391&amp;t=1205063728&amp;e=955751a7f884268a5ab158f592a8a7c9&amp;r=http%3A%2F%2F192.168.1.5%2F2008bt%2FTopicShow.asp%3FThreadID%3D5627&amp;refid=" target=_blank><IMG height=50 alt="" src="http://img.qihoo.com/qhimg/bbs_img/70_50/1/419/575/dfa4f9.gif" width=70 border=0></A></P></textarea><br/>
    <input type='button' value='提交' onclick='Replace()'/>
      

  17.   

    图片链接代码:
    http://www.fluorescencestar.com/imge/LED%20cbdxz.gif