js编辑框   编辑的时候想把内容显示在编辑框文本域里  
content_editor.init('${content}');当content等于内容一:
<p>内容一<p>
一切正常当content等于内容二:
<p>内容二<p>
<p>内容二<p>
<p>内容二<p>
错误就是content里面有换行符的时候  报错
请问各位前辈有没有处理过类似问题  该怎么解决我的项目是使用到的相关技术是 springside3 (struts2.0)+ js+ prototype  

解决方案 »

  1.   

    办法1:放在隐藏的textarea里,调用content_editor.init(textarea.value);办法2:替换${content}中的换行为<br/>,单引号为\'再赋值
      

  2.   

    还可以在后台处理]\r\n(C#),vbcrlf(vbs)为换行符
      

  3.   

    我的textarea  是js生成的 content_editor.init(textarea.value);  
    现在就是想设 textarea.value  难道弄一个隐藏的div 里面放个textarea  用它的value  值的试下 
    方法2  该怎么换啊  换行我看在数据库中  他是以换行的格式保存的  没看到 /r/n  <br/>之类的 该怎么写呢
      

  4.   

    方法1:
    <textarea id="x" style="display:block">${content?html}</textarea> //这个是freeer 的写法。其他技术自己处理方法2:
    content_editor.init('${content.repalce('\r\n','<br/>').repalce("'","\'")}');freeer 的大致方法/
      

  5.   

    高手
    还是不行啊  我太愚顿了  两种方法都没搞定  
    <SCRIPT type=text/javascript>
    var e_bold = true;
    var e_italic = true;
    var e_underline = true;
    var e_JustifyLeft = true;
    var e_JustifyCenter = true;
    var e_JustifyRight = true;
    var e_InsertUnorderedList=true;
    var e_InsertOrderedList=true;
    var e_font = true;
    var e_fontsize = true;
    var e_color = true;
    var e_backcolor = true;
    var e_img = true;
    var e_link = true;
    var e_media = true;
    var e_audio = true;
    var e_uploadimg = true;
    var e_piclink = true;
    var e_toolbarbg = "#f7f7f7";
    content_editor = new webEditor("content_editor" , $("content_div") , 590, 350);
    content_editor.init('${content}');
    </SCRIPT>
    webEditor.prototype.init = function(str)
    {
    this.getUA();
    e_init_content = str;
    this.drawEditor();
    if(e_isOpera)
    {
    this.genObj();
    this.textArea.value = e_init_content;
    return;
    }
    }webEditor.prototype.drawEditor = function()
    {  
    var htmlstr;

    if(e_isOpera)
    {   
    htmlstr = '<div id="'+this.id+'_tid" style="width:'+(this.width+2)+'px;background-color:'+e_toolbarbg+';"></div>'
    +'<div id="'+this.id+'_eid" style="border:1px #808080 solid;width:'+this.width+'px;height:'+this.height+'px;"><div class="it1"><iframe id="'+framename+'" name="'+framename+'" style="width:'+(this.width-2)+'px; height: '+(this.height-2)+'px;" frameborder=0 marginwidth=0 scrolling=auto src="/GamePlatform/js/blog/blank.htm" onfocus="javascript:'+this.id+'.iframeOnfocus();" onblur="javascript:'+this.id+'.iframeOnblur();" onload="javascript:'+this.id+'.postInit();"></iframe></div></div>';

    }
    else
    {  
    var framename = this.id+'_fid_'+(++this.iframeno);
    if (this.toolbarpos == "right")
    {     
    htmlstr = '<div id="'+this.id+'_eid" style="float:left;border:1px #808080 solid;width:'+(this.width-50)+'px;height:'+this.height+'px;"><div class="it1"><iframe id="'+framename+'" name="'+framename+'" style="width:'+(this.width-50-2)+'px; height: '+(this.height-2)+'px;" frameborder=0 marginwidth=0 scrolling=auto src="/GamePlatform/js/blog/blank.htm" onfocus="javascript:'+this.id+'.iframeOnfocus();" onblur="javascript:'+this.id+'.iframeOnblur();" onload="javascript:'+this.id+'.postInit();"></iframe></div></div><div id="'+this.id+'_tid" style="float:left;background-color:'+e_toolbarbg+';"></div><div style="clear:both;"></div>';
    }
    else

    htmlstr = '<textarea style="font-size:14px;width:'+this.width+'px;height:'+this.height+'px;" id="'+this.id+'_aid"  name="'+this.id+'_aid"></textarea>';
    }
    }
    this.editorArea.innerHTML = htmlstr;
    }
      

  6.   

    content_editor.init('${content.repalce('\r\n','<br/>').repalce("'","\'")}');
    我写进去就报做啊