wangEditor——基于bootstrap的富文本编辑器。
引用bootstrap和jquery后,你可以用一句代码制作一个富文本编辑器。
压缩后的wangEditor.min.js只有12KB!
- 引用bootstrap和jQuery
===
使用wangEditor首先需要在您的页面中引用
bootstrap
(以及Font-Awesome
图标库)和jQuery
, 6B1C 果您的系统中没有以上库,可以直接在上面下载。
<link href="bootstrap/css/bootstrap.min.css" rel="stylesheet" />
<link href="Font-Awesome-3.2.1/css/font-awesome.min.css" rel="stylesheet" />
<script src="javascript/jquery-1.10.2.min.js" type="text/javascript"></script>
<script src="bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
- 使用wangEditor
===
引用了
bootstrap
(以及Font-Awesome
图标库)和jQuery
之后,就可以使用wangEditor了。
<div id="divEditor"></div>
<textarea id="txtCode" rows="5" cols="50" style="width:100%"></textarea>
<script src="javascript/wangEditor-1.0.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$('#divEditor').wangEditor({
codeTargetId: 'txtCode', //将源码存储到txtCode
frameHeight: '200px', //默认值为“300px”
//要显示在编辑器中的html源码(用于编辑)
initStr: '<p>欢迎使用<b><wangEditor></b>!请输入文字...</p>'
});
});
</script>
如以上代码:在html中加入一个div,一个textarea;引用wangEditor.min.js;然后执行一步绑定,即可使用wangEditor富文本编辑器!
编辑器内容的源代码会自动保存到textarea中,可直接用javascript获取,通过ajax保存。如下图: