[struts]集成kindeditor出现的问题

本文介绍了KindEditor中两个常见问题的解决方案。一是如何确保textarea中的内容能够被正确获取;二是如何让编辑的内容正常显示,避免html标签被直接输出。通过简单的代码调整即可解决这些问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、

错误现象:使用textarea取不到值,仅为“”。

KindEditor.ready(function(K) {
            var editor1 = K.create('textarea[name="paperContent"]', {
                cssPath : 'kindeditor/plugins/code/prettify.css',
                uploadJson : 'admin/resource/common_uploadFile.action',
                allowFileManager : false,
                afterCreate : function() {
                    var self = this;
                    K.ctrl(document, 13, function() {
                        self.sync();
                        document.forms['form'].submit();
                    });
                    K.ctrl(self.edit.doc, 13, function() {
                        self.sync();
                        document.forms['form'].submit();
                    });
                },
                afterBlur:function(){
                    this.sync();
                }
            });
            prettyPrint();
        });

错误原因:

未知。

解决办法:

如果你的按钮是input[type=submit]的话你不需要考虑这个问题,但如果你使用js提交那么在提交之前要调用一下editor.sync()

函数用以赋值给你的textarea。即需要加上

afterBlur:function(){
this.sync();
}

 

KindEditor.ready(function(K) {
            var editor1 = K.create('textarea[name="paperContent"]', {
                cssPath : 'kindeditor/plugins/code/prettify.css',
                uploadJson : 'admin/resource/common_uploadFile.action',
                allowFileManager : false,
                afterCreate : function() {
                    var self = this;
                    K.ctrl(document, 13, function() {
                        self.sync();
                        document.forms['form'].submit();
                    });
                    K.ctrl(self.edit.doc, 13, function() {
                        self.sync();
                        document.forms['form'].submit();
                    });
                },
                afterBlur:function(){
                    this.sync();
                }
            });
            prettyPrint();
        });

2、

错误现象:编辑内容前台显示不正确,直接将html标签显示出来。

如:

正确显示应该为:

 

错误原因:

使用<s:property value="paper.content"/>显示数据,返回的是字符串,带双引号如:“xxxxx”。

解决办法:

直接用jstl标签${paper.content}。

转载于:https://www.cnblogs.com/wanping/archive/2013/04/11/3006513.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值