第2课:uediotr工具栏的定制

UEditor 工具栏上的按钮列表可以自定义配置,只需要通过修改配置项就可以实现需求

下面看一个示例

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <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" charset="utf-8" src="lang/zh-cn/zh-cn.js"></script>
</head>
<body>
<form action="demo.php" method="post">
    <div>
        <label>标题</label>
        <input type="text" name="title">
    </div>
    <div>
        <label>正文</label>
        <script id="editor" type="text/plain" style="width:1024px;height:500px;"></script>
    </div>
    <div>
        <input type="submit" value="保存">
    </div>
</form>

<script>
    var ue = UE.getEditor('editor', {
        toolbars: [
            ['fullscreen', 'source', 'undo', 'redo', 'bold']
        ],
        autoHeightEnabled: true,
        autoFloatEnabled: true
    });

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

运行的结果如下

从上面的运行结果来看,ueditor的工具栏变成了一行,并且只有五个图标,分别是最大化、源代码、撤消、重做、粗体。实现这样的效果主要通后以下代码实现的

toolbars: [
    ['fullscreen', 'source', 'undo', 'redo', 'bold']
],

如果想实现多行的工具栏,可以写成以下代码

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <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" charset="utf-8" src="lang/zh-cn/zh-cn.js"></script>
</head>
<body>
<form action="demo.php" method="post">
    <div>
        <label>标题</label>
        <input type="text" name="title">
    </div>
    <div>
        <label>正文</label>
        <script id="editor" type="text/plain" style="width:1024px;height:500px;"></script>
    </div>
    <div>
        <input type="submit" value="保存">
    </div>
</form>

<script>
    var ue = UE.getEditor('editor', {
        toolbars: [
            ['fullscreen', 'source', 'undo', 'redo'],
            ['bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript', 'removeformat', 'formatmatch', 'autotypeset', 'blockquote', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', 'selectall', 'cleardoc']
        ],
        autoHeightEnabled: true,
        autoFloatEnabled: true
    });

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

运行的效果如下:

如果不写toolbars,默认所有功能都有

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <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" charset="utf-8" src="lang/zh-cn/zh-cn.js"></script>
</head>
<body>
<form action="demo.php" method="post">
    <div>
        <label>标题</label>
        <input type="text" name="title">
    </div>
    <div>
        <label>正文</label>
        <script id="editor" type="text/plain" style="width:1024px;height:500px;"></script>
    </div>
    <div>
        <input type="submit" value="保存">
    </div>
</form>

<script>
    var ue = UE.getEditor('editor', {
        autoHeightEnabled: true,
        autoFloatEnabled: true
    });

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

运行效果如下:

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

李 书 明

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

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

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

打赏作者

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

抵扣说明:

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

余额充值