使用kindeditor时,取不到textarea里面的值

认真找下原因。
首先描述下我这边KindEditor的错误现象:
1、在IE8/FF下均得不到值;
2、当点击KindEditor的全拼按钮切换到全屏模式输入时,再返回正常模式,可以得到值;
3、我用的是jQuery的点击事件提交表单的,提交,无法得到值;
4、直接用表单的提交按钮可以得到值。

下面以 KindEditor 4.x版本为例说明,先贴上正确的代码:

KindEditor.ready(function(K){
K.create(‘textarea[name="content"]‘,{
themeType: ‘simple’,
resizeType: 1,
uploadJson:‘common/KEditor/upload_json.php’,
fileManagerJson:‘common/KEditor/file_manager_json.php’,
allowFileManager:true,
        //经测试,下面这行代码可有可无,不影响获取textarea的值
        //afterCreate:function(){this.sync();}
        //下面这行代码就是关键的所在,当失去焦点时执行this.sync();
        afterBlur:function(){this.sync();}
});
});

相关说明:
从上面的代码可以看到,解决方法在于最后一行代码,afterBlur:function(){this.sync();},当失去焦点时执行 this.sync();
那么这个 this.sync();函数是干嘛的呢?简单的说:这个函数就是同步KindEditor的值到textarea文本框。
官方解释:
sync()
将编辑器的内容设置到原来的textarea控件里。
参数: 无
返回: KEditor



下面是一个小实例

<script type="text/javascript">
        var editor;
        KindEditor.ready(function (K) {
            editor = K.create('textarea[name=zContent]', {
                items: [
		            'source', '|', 'undo', 'redo', '|', 'preview', 'template', // 'code',
		            'plainpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
		            'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',
		            'superscript', 'clearhtml', 'quickformat', 'selectall', '|', 'fullscreen', '/',
		            'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold',
		            'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'image', 'multiimage',
                //		                'flash', 'media', 'insertfile',
                    'table', 'hr', 'emoticons', 'baidumap', 'pagebreak',
		            'anchor', 'link', 'unlink'
	            ],

                cssPath: 'plugins/code/prettify.css',
                width: '100%',
                height: '500px',
                themesPath: 'themes/',
                langPath: 'lang/',
                pluginsPath: 'plugins/',
                uploadJson: 'upload_json.ashx',
                uUploadParams: "?group=img&groupID=4&w=0&h=0&s=2",
                fileManagerJson: 'FileManager.ashx',
                allowFileManager: true,
                afterBlur: function () { this.sync(); },当失去焦点时执行 this.sync();这个函数就是同步KindEditor的值到textarea文本框。
                afterCreate: function () {
                    var self = this;
                    K.ctrl(document, 13, function () {
                        self.sync();
                        K('form[name=example]')[0].submit();
                    });
                    K.ctrl(self.edit.doc, 13, function () {
                        self.sync();
                        K('form[name=example]')[0].submit();
                    });
                }
            });
            prettyPrint();
            try {
                editor.statusbar.children().eq(1).hide();
            } catch (e) {

            }
            if (window.addEventListener) {
                pastimg();
            } else if (window.attachEvent) {
                pastimg();
            }
        });
    </script>   



  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值