ckeditor取值赋值问题

最近的项目中遇到个很头疼的问题,异步提交表单后需要清空表单数据,项目中文本编辑器是ckeditor,用了好几种方式都无法将提交后的表单清空。

最后发现这种方式可以:

 

				document.form1.reset();
				CKEDITOR.instances.caseText.setData(' ');
 

开始采用jquery的 $("#caseText").val(''); 试试之后发现此方式不成功。

 

采用: document.form1.caseText.value='' 发现也是不可以。

采用:

var o = $("#caseText").cleditor()[0];//关键是这里获取第一个对象,否则upateFrame无法调用 
          $('#caseText').html(' '); 

          o.updateFrame();  
	document.form1.reset();

 

不但没有清除表单值反倒把原来清空的都填回去了。

 

具体说下我配置ckeditor.

 

 

$(function() {
CKEDITOR.editorConfig = function( config )
{/*
	config.language = 'zh-cn';
	config.toolbar = 'Background';
	config.toolbar_Background = [
       ['Bold','Italic','Underline','Strike','-','Subscript','Superscript','RemoveFormat'],
	   ['Cut','Copy','Paste','PasteText','PasteFromWord','-','Undo','Redo'],
        ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock','-','BidiLtr','BidiRtl'],
		['NumberedList','BulletedList','-','Outdent','Indent'],
       '/',
        ['Styles','Format','Font','FontSize'],
        ['TextColor','BGColor'],
		['Link','Unlink'],
		['Image','Flash','Table','HorizontalRule','Smiley','SpecialChar','PageBreak'],
		['Maximize','ShowBlocks']   
    ];
	config.resize_enabled = false;
	config.font_names = 'Arial;Verdana;Times New Roman;Georgia;Tahoma;宋体;黑体;微软雅黑';
	config.disableObjectResizing = false;
*/
	config.language = 'zh-cn';
	config.toolbar = 'Background';
	config.toolbar_Background = [
       ['Bold','Italic','Underline','Strike','-','Subscript','Superscript','RemoveFormat'],
	   ['Cut','Copy','Paste','PasteText','PasteFromWord','-','Undo','Redo'],
        ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
       '/',
        ['FontSize'],
        ['TextColor','BGColor'],
		['Link','Unlink','Table'],
	   ['NumberedList','BulletedList','-','Outdent','Indent'],
	   ['BidiLtr','BidiRtl']
    ];
	//config.entities = false;
	config.resize_enabled = false;
	config.disableObjectResizing = false;
	config.filebrowserImageUploadUrl = 'ckupload?type=Images'; 

};
CKEDITOR.replace( 'caseText', { customConfig : 'config_front.js' }) ;
});

 开始时候为了取值需要,将

var editor = CKEDITOR.replace( 'caseText', { customConfig : 'config_front.js' }) ;

设置成了全局变量,导致每次加载时候会报 存在实例错误。

 

 为了避免类似错误,建议使用:

 

				CKEDITOR.instances.caseText.setData(' ');

方式获取数据。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值