example_UEditor富文本编辑器

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="../Public/plugins/ueditor/ueditor.config.js"></script> <!-- 配置文件 -->
<script src="../Public/plugins/ueditor/ueditor.all.min.js"></script> <!-- 编辑器源码文件 -->
<title>ueditor demo</title>
</head>

<body>
<!-- 加载编辑器的容器 -->
<script id="editor" name="content" type="text/plain" style="800px;height:300px;">

    这里写你的初始化内容
    
</script>
<div id="btn">
    
      <button onclick="getAllHtml()">获得整个html的内容</button>
      <button onclick="getContent()">获得内容</button>
      <button onclick="setContent()">写入内容</button>
      <button onclick="setContent(true)">追加内容</button>
      <button onclick="getContentTxt()">获得纯文本</button>
      <button onclick="getPlainTxt()">获得带格式的纯文本</button>
      <button onclick="hasContent()">判断是否有内容</button>

</div>

<!-- 实例化编辑器 -->
<script type="text/javascript">

    var ue = UE.getEditor('editor');
    
     function getAllHtml() {
        alert(UE.getEditor('editor').getAllHtml())
    }
    
-->    
        function getContent() {
        var arr = [];
        arr.push(UE.getEditor('editor').getContent());
        alert(arr.join("
"));
    }
    
     function setContent(isAppendTo) {
        var arr = [];
        UE.getEditor('editor').setContent('欢迎使用ueditor', isAppendTo);
        alert(arr.join("
"));
    }
    
    function getContentTxt() {
        var arr = [];
        arr.push("使用editor.getContentTxt()方法可以获得编辑器的纯文本内容");
        arr.push("编辑器的纯文本内容为:");
        arr.push(UE.getEditor('editor').getContentTxt());
        alert(arr.join("
"));
    }
    
     function getPlainTxt() {
        var arr = [];
        arr.push("使用editor.getPlainTxt()方法可以获得编辑器的带格式的纯文本内容");
        arr.push("内容为:");
        arr.push(UE.getEditor('editor').getPlainTxt());
        alert(arr.join('
'))
    }
    
     function hasContent() {
        var arr = [];
        arr.push("使用editor.hasContents()方法判断编辑器里是否有内容");
        arr.push("判断结果为:");
        arr.push(UE.getEditor('editor').hasContents());
        alert(arr.join("
"));
    }

    
</script>
</body>

</html>
View Code
原文地址:https://www.cnblogs.com/sihuiming/p/5496371.html