我要往html里面插入代码 需要转换   
类似:text = text.replace(/\n/g,"<br>");
先要将text = text.replace(??这里正则怎么写,"<!--newpage-->");我想像<br>一样 输出就可以了 

解决方案 »

  1.   

            case "br":
    insertHTML("<br>")
    break;
    case "nextpage":
       insertHTML("<!--newpage-->"); //我现在要插入这么到html代码中去             break;function insertHTML(html) {
    if (isModeView()) {return false;}
    eWebEditor.focus();
    if (eWebEditor.document.selection.type.toLowerCase() != "none"){
    eWebEditor.document.selection.clear() ;
    }
    if (sCurrMode!="EDIT"){
    html=HTMLEncode(html);
    }
    eWebEditor.document.selection.createRange().pasteHTML(html) ; 
    }
    function HTMLEncode(text){
    text = text.replace(/&/g, "&amp;") ;
    text = text.replace(/"/g, "&quot;") ;
    text = text.replace(/</g, "&lt;") ;
    text = text.replace(/>/g, "&gt;") ;
    text = text.replace(/\ /g,"&nbsp;");
    text = text.replace(/\n/g,"<br>");
    text = text.replace(/\n/g,"<!--newpage-->");
    text = text.replace(/\t/g,"&nbsp;&nbsp;&nbsp;&nbsp;");
    return text;
    }      
      

  2.   

    直接将这段”<!--newpage-->“设置为那个你要插入的对象的innerHTML不就可以了吗?
      

  3.   

    不明白你说什么,是不是想输入什么就输出什么?那样的话你可以写两个 insertHTML一个调用HTMLEncode一个不调用。