<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>new page</title>
<script>
function a(){
var aObj=document.getElementsByTagName("a");
for(var i=0;i<aObj.length;i++){
aObj[i].parentNode.removeChild(aObj[i]);
}
}
</script>
</head><body onload="a()">
你好,<a href="http://www.xxx.com">链接</a>,测试
</body></html>

解决方案 »

  1.   

    <script language=javascript>
    var str='你好,<a href="http://www.xxx.com">链接</a>,测试'
    re=/<\/?a[^>]*>/g
    alert(str.replace(re,""))
    </script>
      

  2.   

    一楼滴解法有漏洞,应该倒序循环!斑竹滴解法可行,但是无法还原链接!俺给个循环解法,可自由停用也可还原链接!只为好玩,仅供参考!<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
     <head>
      <title>remove and resume attribute</title>
      <meta name="generator" content="editplus" />
      <meta name="author" content="[email protected]" />
      <meta name="keywords" content="javascript" />
      <meta name="description" content="for javascript region of csdn" />
     </head> <body>
    你好,<a href="http://www.no1.com">链接1</a>,测试<br />
    你好,<a href="http://www.no2.com">链接2</a>,测试<br />
    你好,<a href="http://www.no3.com">链接3</a>,测试<br />
    <input type="button" id="btnFreeze" value="Freeze Href" onclick="freezeHref()" />
    <input type="button" id="btnResume" value="Resume Href" onclick="resumeHref()" />
     </body>
    <script type="text/javascript">
    <!--// 冻结 href 属性。
    function freezeHref()
    {
        var colA=document.getElementsByTagName("a");    for(var i=0; i<colA.length; i++)
        {
            if (colA[i].href)
            {
                colA[i].originalHref = colA[i].href;
                colA[i].removeAttribute("href");
            }
        }
    }// 还原 href 属性。
    function resumeHref()
    {
        var colA=document.getElementsByTagName("a");    for(var i=0; i<colA.length; i++)
        {
            if (colA[i].originalHref)
            {
                colA[i].href = colA[i].originalHref;
            }
        }
    }//-->
    </script>
    </html>
      

  3.   

    是符可以用正则表达式试试:var str= '你好,<a href="http://www.xxx.com">链接</a>,测试';
    var reg = /([^<]*)<[^>]*>([^<]*)<[^<]*>([\s\S]*)/;
    WL(str.replace(reg,"$1$2$3"));//输出
      
    -------------------------------------------
    MSN:[email protected] 
    请给我与您交流的机会
      

  4.   

    yixianggao(你我他,三人行必有我师焉!) ,高,实在是高!