Composition.document.body.innerHTML="<%= replace(mailbody, VBCrLf, "") %>"

解决方案 »

  1.   

    您能说的详细些吗?为什麽我运行了您的代码后,给我Undefined variable: VBCrLf out.print(replace(mailbody,VBCrLf,""));的异常呢?
      

  2.   

    "<p>asdasd</p>
    <p>sgsdgds</p>"
    这中间明显有一个回车换行符, 现在就是用替换的方式把回车换行符换掉成:
    "<p>asdasd</p><p>sgsdgds</p>"
    VBCRLF是VBS里定义的一个常量, 就是指回车换行符 chr(10)&chr(13)若是用JS, 则是这样写:
    Composition.document.body.innerHTML="<%= mailbody.replace(/\r\n/mg, "") %>"
      

  3.   

    可是我用的是jsp呀,我哭 T-T
      

  4.   

    我不懂JSP, 可是JSP里总有替换的函数吧. 自己找找资料看看
      

  5.   

    var strvalue=="<%= replace(mailbody, VBCrLf, "") %>"
    Composition.document.body.innerHTML=strvalue.replace(/\r\n/mg,"")
      

  6.   

    字符串从数据库里读到页面时,通常要经过处理。
    比如果<input value="aaaa">如果数据库里的值是aa"aa,不处理就直接使用的话,就会产生失真。
    对于产生失真或的产生错误的特殊字符,都要进行处理。Script里面的,可以这样调用
    <%=CommStr.jsEncoder(yourString)%>/*
     * Created by Seamus
     * Updated on 2004-10-21 by JK
     *
     */
    package com.jk.util;public class  CommStr
    {
      /**
      *replace the old string to new string in the given destination string.
      */
      public static java.lang.String strReplace(java.lang.String destStr, java.lang.String oldStr, java.lang.String newStr)
      {
        if(destStr==null)
          return "";
        String tmpStr = destStr;
        int foundPos = tmpStr.indexOf(oldStr);
        while (foundPos>=0)
        {
          tmpStr = tmpStr.substring(0,foundPos) + newStr + tmpStr.substring(foundPos + oldStr.length(),tmpStr.length());
          foundPos = tmpStr.indexOf(oldStr,foundPos+newStr.length());
        }
        return tmpStr;
      }  /**
      *Encode for HTML.
      */
      public static String htmlEncoder(String str)
      {
        if(str==null || str.equals(""))
          return "";
        String res_str;
        res_str=strReplace(str,"<","&lt;");
        res_str=strReplace(str,">","&rt;");
        res_str=strReplace(str,"\"","&quot;");
        res_str=strReplace(str,"'","&#039;");
        return res_str;
      }  /**
      *Encode for HTML-Text.
      */
      public static String htmlTextEncoder(String str)
      {
        if(str==null || str.equals(""))
          return "";
        String res_str;
        res_str=strReplace(str,"<","&lt;");
        res_str=strReplace(str,">","&rt;");
        res_str=strReplace(str,"\"","&quot;");
        res_str=strReplace(str,"'","&#039;");
        res_str=strReplace(str," ","&nbsp;");
        res_str=strReplace(str,"\r\n","<br>");
        res_str=strReplace(str,"\r","<br>");
        res_str=strReplace(str,"\n","<br>");
        return res_str;
      }  /**
      *Encode for URL.
      */
      public static String urlEncoder(String str) {
        return java.net.URLEncoder.encode(str) ;
      }  /**
      *Encode for XML.
      */
      public static String xmlEncoder(String str)
      {
        if(str==null || str.equals(""))
          return "";
        String res_str;
        res_str=strReplace(str,"&","&amp;");
        res_str=strReplace(res_str,"<","&lt;");
        res_str=strReplace(res_str,">","&gt;");
        res_str=strReplace(res_str,"\"", "&quot;");
        res_str=strReplace(res_str,"\'", "&acute;");
        return res_str;
      }  /**
      *Encode for SQL.
      */
      public static String sqlEncoder(String str)
      {
        if(str==null || str.equals(""))
          return "";
        String res_str;
        res_str=strReplace(str,"'","''");
        return res_str;
      }  /**
      *Encode for Javascript.
      */
      public static String jsEncoder(String str)
      {
        if(str==null || str.equals(""))
          return "";
        String res_str;
        res_str=strReplace(str,"'","\\'");
        res_str=strReplace(str,"\"","\\\"");
        res_str=strReplace(str,"\r\n","\\\n");
        res_str=strReplace(str,"\n","\\\n");
        res_str=strReplace(str,"\r","\\\n");
        return res_str;
      }}