冬天来了,春天还会远吗|

进阶的哈姆雷特

园龄:7年1个月粉丝:3关注:8

quill 富文本编辑器自定义按钮

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <link href="https://cdn.quilljs.com/1.0.0/quill.snow.css" rel="stylesheet" />


    <div id="toolbar">
        <button class="ql-bold"></button>
        <button class="ql-italic"></button>
        <!-- new add -->
        <button id="add_hr_btn">hr</button>
    </div>

    <div id="editor">
        <p>Hello World!</p>
    </div>

</body>

<!-- Include the Quill library -->
<script src="https://cdn.quilljs.com/1.0.0/quill.js"></script>

<!-- Initialize Quill editor -->
<script>
    class HR {
        constructor(quill, options) {
            this.quill = quill;
            this.options = options;

            this.container = document.querySelector(options.container);

            const btn = document.getElementById('add_hr_btn');
            btn.onclick = function () { this.update(); }.bind(this);
            // this.update();
        }

        update() {
            let p = document.createElement('p');
            p.setAttribute('style', 'border-bottom: 1px solid red;');
            this.container.appendChild(p);
        }
    }

    Quill.register('modules/hr', HR);

    var quill = new Quill('#editor', {
        modules: {
            toolbar: {
                container: '#toolbar'
            },
            hr: {
                container: '.ql-editor'
            }
        },
        theme: 'snow',
    });
</script>

</html>

本文作者:进阶的哈姆雷特

本文链接:https://www.cnblogs.com/lbx6935/p/17356162.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   进阶的哈姆雷特  阅读(515)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起