关于kindeditor提交无法获取到获取到值的问题

今天做一个功能,需要用到富文本编辑器,之前同事已经配置好插件,太好了,直接拿过来用。

    这时候诡异的事情发生了,同事用的一切正常,而我用却获取不到值。百思不得其解,度娘求解。发现是我同事是直接form表单提交,而我这边是用JS提交的,区别在此。
    问题的解决办法其实也很简单,在js提交form之前加一句话document.getElementById("content1").value=KE.util.getData('content1');

//先获得content7的值
var content7 = document.getElementById("content7").value=KE.util.getData('content7');
//把这个content7赋值给input
$("#content").val(content7);
//当提交的时候,通过input把值传到后台
<input id="content" name="notice.content" type="hidden" value=""/>
$("#pagerForm").submit();

下面是我写的jsp的一个例子

注意:使用kindeditor,当给内容换行或给字体颜色改变的时候,kindeditor会自动转化成对应的style样式

kindeditor的js
链接: https://pan.baidu.com/s/1kWv3js7 密码: syhj 

<%@page contentType="text/html; charset=utf-8"%>
<%@page session="false"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ page isELIgnored="false" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    String isvali=(String)request.getSession().getAttribute("isvali");
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<link href="<%=path %>/web/css/style.css" rel="stylesheet" type="text/css" />
<link href="<%=path %>/web/css/select.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" type="text/css" href="<%=path%>/web/mobile/css/lCalendar.css"/>
<script type="text/javascript" src="<%=path %>/web/js/jquery.js"></script>
<script type="text/javascript" src="<%=path %>/web/js/My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript" src="<%=path %>/web/js/My97DatePicker/calendar.js"></script>
<script type="text/javascript" charset="utf-8" src="<%=path %>/web/editor/kindeditor.js"></script>



<script type="text/javascript">
	KE.show({
        id : 'content7',
        cssPath : './index.css'
    });
	function ifSubmit(){
		var code = $("#name").val().trim();
		var name = $("#d423").val().trim();
		var content7 = document.getElementById("content7").value=KE.util.getData('content7');
		if(code==undefined || name==undefined || code==null || name==null || code=="" || name=="" || content7==null || content7==undefined || content7==""){
			return alert("信息不能未空!");
		}
		$("#content").val(content7);
		$("#pagerForm").submit();
	}
</script>
</head>

<body>

	<div class="place">  
    <span>位置:</span>
    <ul class="placeul">
    <li><a href="#">首页</a></li>
    <li><a href="#">前端管理</a></li>
    </ul>
    </div>
    
  <form id="pagerForm"  action="<%=path%>/notice!insertNotice.do?" method="post" >   
  
    <div class="formbody">
    
    <div class="formtitle"><span>公告添加</span></div>
	
		<input type="hidden" id="sid" name="sid" value="${sid}"/>    
			
    <ul class="forminfo">
	    <li><label>公告名</label><input id="name" name="notice.name" type="text" style="width:700px;" class="dfinput" value=""/></li>
	    <li>
	    	<label>发起时间</label>
	    	<input id="d423" name="notice.date" class="dfinput" value="" class="Wdate" type="text" style="width:700px;" readonly="readonly" οnfοcus="WdatePicker({el:'d423',dateFmt:'yyyy-MM-dd HH:mm:ss'})"/>
	    </li>
	    <li>
	    	<label>公告内容</label>
	    	<input id="content" name="notice.content" type="hidden" value=""/>	    	
	    	<textarea  id="content7" class="dfinput" style="width:700px;height:500px;visibility:hidden;"></textarea>
	    </li>
    </ul>

    
    </div>
    
    <div style="position: relative;width: 300px;height: 50px;margin-top;50px;margin-left: 60px;">
    	<div style="position: absolute;margin-left: 180px;"><input οnclick="ifSubmit()" type="button" class="btn" value="确认保存"/></div>
    	<div style="position: absolute;margin-left: 380px;"><input οnclick="window.history.back(-1); " type="button" class="btn" value="返回" /></div>
    </div>

</form>
</body>

</html>


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值