简体   繁体   English

如何将CKEditor的默认值设置为空白?

[英]How to set CKEditor default value to blank?

I am using CKEditor in my Rails project 我在Rails项目中使用CKEditor

The view looks like this: view如下所示:

<%= cktext_area_tag "editor_name","", :style=>"width:115px; height:19px; border:#d1d1d1 1px solid;  background:#cfcfcf" %>

There is no content in the editor when it is loaded. 加载时,编辑器中没有内容。 But while checking the console I could see this: 但是在检查console我可以看到以下内容:

    > var editor_val = CKEDITOR.instances.editor_name.document.getBody().getChild(0).getText() ;
    < undefined
    > editor_val
    < "
      "
    > editor_val.length
    < 1

I want the CKEditor default value to be blank. 我希望CKEditor的默认值为空白。 How is it possible? 这怎么可能?

CKEditor is never truly empty, if you think about DOM, not the data: 如果考虑DOM而不是数据,CKEditor永远不会真正为空:

CKEDITOR.instances.editor.setData( '' );
CKEDITOR.instances.editor_name.editable().getText().length;
1
CKEDITOR.instances.editor_name.editable().getText().charCodeAt( 0 );
10
CKEDITOR.instances.editor_name.editable().getHtml();
"<p><br></p>" 
CKEDITOR.instances.editor_name.getData().length;
0

That "persistent" white character (10) ( do not confuse with with keyCode ) is a new line , hardly a reminiscence of <br> which is to enable editing in CKEditor and may differ depending on browser/OS. “持久”白色字符(10)( 不要与keyCode混淆 )是换行符 ,几乎不会让人联想到<br>以便在CKEditor中进行编辑,并且可能会因浏览器/ OS而异。 It's an internal starting point for CKEditor to display the caret and the initial collapsed selection which means you should not rely on it. 这是CKEditor显示插入符号和初始折叠选择的内部起点,这意味着您不应该依赖它。

Since the only safe method of obtaining CKEditor content is: 由于获取CKEditor内容的唯一安全方法是:

CKEDITOR.instances.editor_name.getData();

I would suggest stripping tags on the server-side or CKEDITOR.tools.trim() if you really want to follow the editable().getText() way. 如果您真的想遵循editable().getText()方法,建议在服务器端或CKEDITOR.tools.trim()上剥离标签。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM