---
title: "使用xheditor二次编辑内容时，内容不完整"
url: "https://lerry.me/post/2011/06/problem_of_xheditor"
date: 2011-06-26T09:39:00.000Z
updated: 2026-09-09T08:28:18.947Z
tags:
language: zh-CN
---

# 使用xheditor二次编辑内容时，内容不完整

一直以来，我的博客是没有重新编辑已发表文章功能的，[今天终于更新了](https://lerry.me/post/2011/03/to-do-list)，主要是使用xheditor时有一些问题，这是我在[xheditor论坛上的提问](http://forum.xheditor.com/thread-918-1-1.html)：

 "我在使用xhEditor时遇到了一个问题，我是把它用在我的独立博客上的，但是我发现，编写后提交的文章，再次编辑会出现问题，比如我写了一篇文章 ，比较短，编辑后源码如下  

```
<span style="font-family: Tahoma, Arial; "></span>  
<div class="commentbox-content" style="padding-top: 3px; padding-right: 3px; padding-bottom: 14px; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(255, 255, 255); padding-left: 15px; ">  
<br />  
还是linux 好用  
</div>  
  ```

但是再次编辑时就变成了  

```
<div class="commentbox-content" style="padding-top: 3px; padding-right: 3px; padding-bottom: 14px; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(255, 255, 255); padding-left: 15px; ">  
<br />  
还是linux 好用  
</div>  
" >  
```
  
如果是  

```
<p>  
  
你好啊，  
</p>  
<p>  
  
<strong>测试一下</strong>  
</p>  
```  

就什么也没有了  
  
  
总的来说，提交后再次从数据库读取，会  
1.前面少了很多字符  
2.后面会自动出现" >  
我二次编辑是从数据库读取后对textarea的value进行设置  
查看数据库发现保存的内容是完整、正常的  

此时查看编辑页面源文件发现内容完整，但是显示出来的却有问题，请问这是怎么回事？

收到的回答：

无论是否用可视化编辑器，重新编辑，必需要对数据库中的值进行转义，再放入textarea内。  
就是说，你要保证<textarea>和</textarea>之间不出现任何的HTML代码，也就是不允许出现<和>两个符号。  
得到回答后，我又看了下源码，我是通过value=""赋值的，更改为直接写在<textarea>和</textarea>之间，然后对从数据库读取内容进行转义 editpost.content = web.htmlquote(editpost.content)，然后就一切正常了。

再次赞一下[xhEditor](http://xheditor.com/)官方论坛的管理员，总是一语道破玄机，对于我们免费用户也热心指点。
