---
title: "fckeditor 上传 转义字符相关"
author: "wangleide414"
date: "2012-12-12T15:21:17Z"
tags: []
categories: ["编程语言"]
slug: "fckeditor"
draft: false
lastmod: "2012-12-12T15:21:17Z"
id: 1746491
url: "https://wangleide414.iteye.com/blog/1746491"
---

大家做web开发，可能会用到 编辑器，编辑器写很多文字上传可到后台就是表情了。比如&lt;img&gt; 等标签，还有相关的单引号，双引号，但是当从后来读取到前台显示的时候，会出现很多问题，尤其是赋值给js 的变量的时候，可能需要用转义字符才能解决相关问题。

 

本人是这样解决此问题的。以下是相关的ExtJs的部分代码

```
	var win = new Ext.Window({
		title : "管理学校简介",
		layout : 'fit',
		width : '100%',//1300
		height : 600,//600
		closeAction : 'hide',
		modal : true,
		buttonAlign : 'center',
		buttons : [{
					text : "确定修改",
					type : 'submit',
					handler : function() {
						Ext.get('code').dom.value = editorInstance
								.GetXHTML(true);//获取fckeditor内容赋给textarea  
						var str = Ext.getCmp("code");
						if (fckeditorFormPanel.form.isValid()){//验证通过      
							fckeditorFormPanel.form.doAction('submit', {
										url : '../content.do?method=updateContent',
										params:{
											'id' : '00001'
										},
										method : 'post',
										waitMsg : '正在提交,请稍等...',
										success : function(form, action) {//成功返回        
											Ext.Msg.alert("提示消息", "添加成功");
										},
										failure : function(form, action) {//失败返回      
											Ext.Msg.alert("提示消息", "添加数据发生了异常");
										}
									});
						}
					}
		}],
		items : fckeditorFormPanel
	});
	win.show();
	//	var oFCKeditor = new FCKeditor('code', 1100, 600); //编辑器的大小
	var oFCKeditor = new FCKeditor('code');
	oFCKeditor.Height = '100%';
	oFCKeditor.Width = '100%';
	oFCKeditor.BasePath = "../fckeditor/"; //编辑器路径  
	oFCKeditor.ToolbarSet = 'Default'; //工具栏样式主题，经过测试其他的主题还要到fckconfig.js下去修改。  
	oFCKeditor.ReplaceTextarea();
```

 

编辑器的内容直接保存到后台数据库即可，包括对应的标签等内容，在显示的时候

```
<div id="stockcode" style="display:none">
			<%=content.getContent()%>
		</div>
```

```
显示到一个div 中，但是是隐藏的，然后再js 中调用 stockcode.innerHTML 即可用html 识别的方式显示出之前保存的
```

```
内容，当时也可用stockcode.innerText ，不过这种方法只显示内容，过滤了html 中的标签
```