把注释后面的单引号替换成 ´ 双引号替换成 "
求个高效的方法,因为文件很大。
&nbsp;&nbsp;&nbsp;\n<br/>//aaa we're aaa aaa "xxx"\n<br/>
  function yyy() {
    var s = '不替换';
  }
//aaa we're aaa aaa aaa\n<br/>
  //xxx we're xxx xxx "xxx"\n<br/>script type="text/javascript">
function goit() {
var code = document.getElementById("m").value;
//不会写了
alert(code);
document.getElementById('result').innerHTML = code;
}
</script>
<body>
<form method="post" name="form1">
<div align="center">
<textarea rows="18" name="S1" style="width:100%" id="m">
// Look for the case where we're accessing a style value
     if ( name.constructor == String )
      if ( value === undefined )
        return this[0] && jQuery[ type || 'attr' ]( this[0], name );
      else {
        options = {};
        options[ name ] = value;
      }
// Check to see if were sett'ing style values

/** Look for the case where we're accessing a style value **/
     if ( name.constructor == String )
      if ( value === undefined )
        return this[0] && jQuery[ type || 'attr' ]( this[0], name );
      else {
        options = {};
        options[ name ] = value;
      }
/** Look for the case where we're accessing a style value **/
// Check to see if we're setting style values
</textarea>
</div>
<input type="button" value="HTML" onclick="return goit()" />
<input type="reset" value="清空内容" />
</form>

<div id="result"></div>

</body>

解决方案 »

  1.   


    <html>
        <head>
            <meta http-equiv="content-type" content="text/html; charset=utf-8">
            <META http-equiv="Content-Style-Type" content="text/css">
         
        </head>
        <script language=javascript>
        
    function goit(){
           var s=document.getElementById("m").innerHTML;   
           var a=s.replace(/'/g,"&acute ");
           var a=s.replace(/"/g,"&quot ");
           document.getElementById('result').innerHTML = a;
    }
            window.onload=function(){          
            }    </script>
        <body>
            <form method="post" name="form1">
                <div align="center">
                    <textarea rows="18" name="S1" style="width:100%" id="m">
                        // Look for the case where we're accessing a style value
                        if ( name.constructor == String )
                          if ( value === undefined )
                            return this[0] && jQuery[ type || 'attr' ]( this[0], name );
                          else {
                            options = {};
                            options[ name ] = value;
                          }
                        // Check to see if were sett'ing style values
                        
                        /** Look for the case where we're accessing a style value **/
                        if ( name.constructor == String )
                          if ( value === undefined )
                            return this[0] && jQuery[ type || 'attr' ]( this[0], name );
                          else {
                            options = {};
                            options[ name ] = value;
                          }
                        /** Look for the case where we're accessing a style value **/
                        // Check to see if we're setting style values
                    </textarea>
                </div>
                <input type="button" value="HTML" onclick="return goit()" />
                <input type="reset" value="清空内容" />
            </form>
            
            <div id="result"></div>
            
        </body>
    </html>
      

  2.   

    写错,是<html>
        <head>
            <meta http-equiv="content-type" content="text/html; charset=utf-8">
            <META http-equiv="Content-Style-Type" content="text/css">
         
        </head>
        <script language=javascript>
        
    function goit(){
           var s=document.getElementById("m").innerHTML; 
       
           var a=s.replace(/'/g,"&acute ");       var c=a.replace(/"/g,"&quot ");       document.getElementById('result').innerText = c;
    }
            window.onload=function(){          
            }    </script>
        <body>
            <form method="post" name="form1">
                <div align="center">
                    <textarea rows="18" name="S1" style="width:100%" id="m">
                        // Look for the case where we're accessing a style value
                        if ( name.constructor == String )
                          if ( value === undefined )
                            return this[0] && jQuery[ type || 'attr' ]( this[0], name );
                          else {
                            options = {};
                            options[ name ] = value;
                          }
                        // Check to see if were sett'ing style values
                        
                        /** Look for the case where we're accessing a style value **/
                        if ( name.constructor == String )
                          if ( value === undefined )
                            return this[0] && jQuery[ type || 'attr' ]( this[0], name );
                          else {
                            options = {};
                            options[ name ] = value;
                          }
                        /** Look for the case where we're accessing a style value **/
                        // Check to see if we're setting style values
                    </textarea>
                </div>
                <input type="button" value="HTML" onclick="return goit()" />
                <input type="reset" value="清空内容" />
            </form>
            
            <div id="result"></div>
            
        </body>
    </html>
      

  3.   

    //把注释后面的单引号替换成 &acute; 双引号替换成 &quot; var sText="注释内容";var sResult=sText.split("'").join("&acute");sResult=sResult.split('"').join("&quot");
      

  4.   

    这样会不会快一点?
    var str = '&nbsp;&nbsp;&nbsp;\n<br/>//aaa we\'re aaa aaa "xxx"\n<br/> //xxx we\'re xxx xxx "xxx"\n<br/>',r = {"'":"&acute;",'"':'&quot;'}alert(str.replace(/'|"/g,function($0){return r[$0];}))
      

  5.   

    晕.看错了,替换注释的话应该这样做<html>
        <head>
            <meta http-equiv="content-type" content="text/html; charset=utf-8">
            <META http-equiv="Content-Style-Type" content="text/css">
         
        </head>
        <script language=javascript>
        
    function goit(){
           var s=document.getElementById("m").innerHTML;       var matchx=/\n/;
          var match1=/\/\/.+'.+/g;
          var match2=/\/\/.+".+/g;      var a=s.split(matchx);
          var ret=[];
          var tmp;
          for(var i=0;i<a.length;i++){
             if(match1.test(a[i])||match2.test(a[i])){
                tmp=a[i].replace(/'/g,"&acot ");
                ret[i]=tmp.replace(/"/g,"&quot ")
             }else{
               ret[i]=a[i];
             }
          }
          alert(ret)       document.getElementById('result').innerText = ret.join(",");
    }
            window.onload=function(){          
            }    </script>
        <body>
            <form method="post" name="form1">
                <div align="center">
                    <textarea rows="18" name="S1" style="width:100%" id="m">
                        // Look for the case where we're accessing a style value
                        if ( name.constructor == String )
                          if ( value === undefined )
                            return this[0] && jQuery[ type || 'attr' ]( this[0], name );
                          else {
                            options = {};
                            options[ name ] = value;
                          }
                        // Check to see if were sett'ing style values
                        
                        /** Look for the case where we're accessing a style value **/
                        if ( name.constructor == String )
                          if ( value === undefined )
                            return this[0] && jQuery[ type || 'attr' ]( this[0], name );
                          else {
                            options = {};
                            options[ name ] = value;
                          }
                        /** Look for the case where we're accessing a style value **/
                        // Check to see if we're setting style values
                    </textarea>
                </div>
                <input type="button" value="HTML" onclick="return goit()" />
                <input type="reset" value="清空内容" />
            </form>
            
            <div id="result"></div>
            
        </body>
    </html>
      

  6.   

    俺说个别的,单引号最好不要用&acute;
    用&#39;