javascript html 형식 제거

3182 단어 JavaScript
function replacehtml()  
{  
    var str="";//      
  
    function setStr()  
    {  
        this.str=arguments[0];  
    }  
    function getStr()  
    {  
        return this.str;  
    }  
      
    //   html    
    function replace()  
    {  
        if(arguments.length>0)  
        {  
            this.str=arguments[0];  
        }  
        this.str=this.str.replace(/<font.*?<\/font>/g,"");//font    
        this.str=this.str.replace(/<script .*?<\/script>/ig,""); //script    
        this.str=this.str.replace(/<(a|img)/ig, "@@@$1"); //img    
        this.str=this.str.replace(/<[^>a]*>/ig, ""); //a    
        this.str=this.str.replace(/@@@(a|img)/ig, "<$1"); //a|img  
        this.str=this.str.replace(/<br>/ig,"");//    
        return this.str;  
    }  
      
    //    html    
    function replaceAll()  
    {  
        if(arguments.length>0)  
        {  
            this.str=arguments[0];  
        }  
        this.str=this.str.replace(/<[^>]*>/g, "");  
        this.str=this.str.replace(/\/r\/n/g, "<br />");  
        return this.str;  
    }  
      
    var o={};  
    o.setStr=setStr;  
    o.getStr=getStr;  
    o.replace=replace;  
    o.replaceAll=replaceAll;  
    return o;  
}  

 //====================테스트 = = = = = = = = = = = = = =
var str="<font color=\"#c60a00\">1818</font>   ,<font color=\"#c60a00\">1818</font>     《    》  ,    ,   ,OTC..</font></a><br><font size=-1><font color=\"#c60a00\">1818</font>   ,<font color=\"#c60a00\">1818</font>     ,《    》  ,               ,      ,   ,OTC  ,    ,    ,         ,     ,            !<br><font color=\"#008000\"> www.1818vip.com/ 87K 2009-10-22  </font>";  
document.write("  :<br/>"+str+"<br/>");  
var a=new replacehtml();//     
//  1  
a.setStr(str);  
a.replaceAll();  
document.write("  1:<br/>"+a.getStr()+"<br/>");   
  
//  2  
a.setStr(str);  
a.replace();  
document.write("  2:<br/>"+a.getStr()+"<br/>");   
  
//  3  
a.replace("<font color='#ff0000'><a href='#' mce_href='#'>aaa</a></font><br/>bbb<li>ccc</li>");  
document.write("  3:<br/>"+a.getStr()+"<br/>");   
  
//  4  
a.replaceAll("<font color='#ff0000'><a href='#' mce_href='#'>aaa</a></font><br/>bbb<li>ccc</li>");  
document.write("  4:<br/>"+a.getStr());

좋은 웹페이지 즐겨찾기