<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>获取内容</title>
<style type="text/css">
/* table 样式 */
table {
border-top: 1px solid #ccc;
border-left: 1px solid #ccc;
}
table td,
table th {
border-bottom: 1px solid #ccc;
border-right: 1px solid #ccc;
padding: 3px 5px;
}
table th {
border-bottom: 2px solid #ccc;
text-align: center;
}
/* blockquote 样式 */
blockquote {
display: block;
border-left: 8px solid #d0e5f2;
padding: 5px 10px;
margin: 10px 0;
line-height: 1.4;
font-size: 100%;
background-color: #f1f1f1;
}
/* code 样式 */
code {
display: inline-block;
*display: inline;
*zoom: 1;
background-color: #f1f1f1;
border-radius: 3px;
padding: 3px 5px;
margin: 0 3px;
}
pre code {
display: block;
}
/* ul ol 样式 */
ul, ol {
margin: 10px 0 10px 20px;
}
</style>
<script type="text/javascript" src="wangEditor.min.js"></script>
</head>
<body>
<button id="btn1">获取hmtl</button>
<button id="btn2">获取text</button>
<div id="div1">
<p>使用wangeditor编辑器</p>
</div>
<script>
var E=window.wangEditor;
var editor=new E("#div1");
editor.create();
document.getElementById('btn1').addEventListener('click', function () {
// 读取 html
alert(editor.txt.html())
}, false)
document.getElementById('btn2').addEventListener('click', function () {
// 读取 text
alert(editor.txt.text())
}, false)
</script>
</body>
</html>
需要注意的是从编辑器获取html不包含任何样式的纯html,可以自定义样式。