百度UEditor富文本编辑器



<!DOCTYPE html>
<html lang="en">
<head>
    <include file="include/header"/>
    <link href="__PUBLIC__/icheck-1.x/skins/all.css" rel="stylesheet">

    <!-- 配置文件 -->
    <script type="text/javascript" src="__PUBLIC__/UEditor/ueditor.config.js"></script>
    <!-- 编辑器源码文件 -->
    <script type="text/javascript" src="__PUBLIC__/UEditor/ueditor.all.js"></script>
    <script type="text/javascript" charset="utf-8" src="__PUBLIC__/UEditor/lang/zh-cn/zh-cn.js"></script>
</head>
<body>


<body>
<section class="wrapper">
    <div class="row">
        <div class="col-lg-12">
            <section class="panel" style="border-top: 2px solid #2E3238;">
                <div class="panel-body" id="panel-bodys">
                    <form name="myform" class="form-horizontal tasi-form" action="" method="post">
                        <table class="table table-striped table-advance table-hover" id="contenttable">
                            <tbody>
                            <tr>
                                <td>
                                    <div class="col-sm-12 input-group">
                                        <!-- 加载编辑器的容器 -->
                                        <script id="container" name="content" type="text/plain">{$content}</script>
                                    </div>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <div class="contentsubmit text-center">
                                        <input type="hidden" name="modelid" value="">
                                        <input type="hidden" name="old_status" value="">
                                        <input data-num="1" type="button" id="save" class="save-bt btn btn-info"
                                               value="保 存"> &nbsp;&nbsp;&nbsp;
                                        <input data-num="0" type="reset" class="btn btn-primary" value="重 置">
                                    </div>
                                </td>
                            </tr>
                            </tbody>
                        </table>
                    </form>
                </div>
            </section>
        </div>
    </div>
</section>

<!-- 实例化编辑器 -->
<script type="text/javascript">
    var ue = UE.getEditor('container');
</script>

<script type="text/javascript">

    //保存内容
    $("#save").on('click', function () {
        console.log('保存内容');

        $.ajax({
            url: "/Admin/ContentSetting/about_us",
            type: "post",
            data: {"": ""},
            async: false,
            success: function (datas) {
                if (datas.error_code != 200) {
                    layer.msg(datas.error_msg, {time: 1200, icon: 5});
                    return false;
                } else {
                    layer.msg('修改成功!', {time: 1200, icon: 6});
                    table.reload('datatable');
                }
            }
        });
    });

    //重置内容
    $("input:reset").on('click', function () {
        ue.setContent('');
    });

</script>
</body>
</body>
</html>


UEditor API 文档:http://ueditor.baidu.com/doc

常用:


ready(Function fn)编辑器对外提供的监听ready事件的接口, 通过调用该方法,达到的效果与监听ready事件是一致的
destroy()销毁编辑器实例,使用textarea代替
render(String containerId)渲染编辑器的DOM到指定容器
render(Element containerDom)渲染编辑器的DOM到指定容器
setHeight(Number number)设置编辑器高度
getContent()获取编辑器的内容
getContent(Function fn)获取编辑器的内容。 可以通过参数定义编辑器内置的判空规则
getAllHtml()取得完整的html代码,可以直接显示成完整的html文档
getPlainTxt()得到编辑器的纯文本内容,但会保留段落格式
getContentTxt()获取编辑器中的纯文本内容,没有段落格式
setContent(String html)设置编辑器的内容,可修改编辑器当前的html内容
setContent(String html, Boolean isAppendTo)设置编辑器的内容,可修改编辑器当前的html内容
focus()让编辑器获得焦点,默认focus到编辑器头部
focus(Boolean toEnd)让编辑器获得焦点,toEnd确定focus位置
hasContents()检查编辑区域中是否有内容
hasContents(Array tags)检查编辑区域中是否有内容,若包含参数tags中的节点类型,直接返回true
reset()重置编辑器,可用来做多个tab使用同一个编辑器实例
setEnabled()设置当前编辑区域可以编辑
setDisabled()设置当前编辑区域不可编辑
setDisabled(String except)设置当前编辑区域不可编辑,except中的命令除外
setDisabled(Array except)设置当前编辑区域不可编辑,except中的命令除外
setShow()显示编辑器
setHide()隐藏编辑器
getLang(String path)根据指定的路径,获取对应的语言资源
getContentLength()计算编辑器html内容字符串的长度
getContentLength(Boolean ingoneHtml)计算编辑器当前纯文本内容的长度
addInputRule(Function rule)注册输入过滤规则
filterInputRule(UE.uNode root)执行注册的过滤规则
addOutputRule(Function rule)注册输出过滤规则
filterOutputRule(UE.uNode root)根据输出过滤规则,过滤编辑器内容

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

dnbug Blog

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值