ueditor是百度公司推出的在线富文本编辑器。
官网http://ueditor.baidu.com/website/ 可下载源码包(带php的),放入带有后台的环境中运行。
官网中的ue演示和api以及文档都可以做很好的参考
上传表单
表单中除了一般的文字内容,还包括图片,文件,在线地图等。
一般文字
加载文件
<script type="text/javascript" charset="utf-8" src="ueditor.config.js"></script> <script type="text/javascript" charset="utf-8" src="ueditor.all.min.js"> </script> <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript" charset="utf-8" src="lang/zh-cn/zh-cn.js"></script>
body
<form name="ueditor" id="ueditor"> <script id="editor" type="text/plain" style="width:1024px;height:500px;"></script> //这是你的富文本容器。id可任意命名 </form>
<button>subit</button>
script
var ue = UE.getEditor('editor'); $("#submit").click(function(){ var data = UE.getEditor('editor').getContent(); $.ajax({ cache: true, type: "GET", url: "demo.json",
data: {
"data": data
},
async: false, error: function(request) { alert("Connection error"); }, success: function(){ alert("success"); } }); });
如果用传统的form submit(意味着form里要有name,method,action这些字段)提交,控制台传输的数据是这样
editorValue:<p>dasdasdsa</p>
但用ajax的话,就要用到这个来获取内容UE.getEditor('editor').getContent()。
传输给后台的字段这样