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 中国大陆许可协议进行许可。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步