---
title: "jquery无法获取kindeditor编辑器中textarea值的解决办法"
author: "泽.."
date: "2013-12-22T20:17:11Z"
tags: []
categories: ["Web前端"]
slug: "jquery-kindeditor-textarea"
draft: false
lastmod: "2013-12-22T20:17:11Z"
id: 1993514
url: "https://dzc.iteye.com/blog/1993514"
---

jsp页面：

 &lt;script&gt;  
  KindEditor.ready(function(K) {  
   K.create('textarea\[id="content2"]', {  
    cssPath : '${pageContext.request.contextPath}/resources/kindeditor/plugins/code/prettify.css',  
    uploadJson : '${pageContext.request.contextPath}/resources/kindeditor/jsp/upload\_json.jsp',  
    fileManagerJson : '${pageContext.request.contextPath}/resources/kindeditor/jsp/file\_manager\_json.jsp',  
    afterBlur: function(){this.sync();//假如没有这一句，获取到的id为content的值空白}  
   });  
   prettyPrint();  
  });  
 &lt;/script&gt;

&lt;textarea id="content“ textarea&gt;

&lt;script type="text/javascript"&gt;

$("#content").val();

 &lt;/script&gt;

 

 

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

这一句的作用：当失去焦点时执行 this.sync();  
这个函数作用是同步KindEditor的值到textarea文本框。  
官方文档解释：  
sync()  
将编辑器的内容设置到原来的textarea控件里。  
参数: 无