posts - 91,  comments - 2,  views - 11万
quill版本1.3.7

xxx.vue

复制代码
<script>
export default {
  data() {
    return {
      tooltips: [
        { choice: '.ql-bold', title: '加粗' },
        { choice: '.ql-italic', title: '斜体' },
        { choice: '.ql-underline', title: '下划线' },
        { choice: '.ql-header', title: '段落格式' },
        { choice: '.ql-strike', title: '删除线' },
        { choice: '.ql-blockquote', title: '块引用' },
        { choice: '.ql-code', title: '插入代码' },
        { choice: '.ql-code-block', title: '插入代码段' },
        { choice: '.ql-font', title: '字体' },
        { choice: '.ql-size', title: '字体大小' },
      ],
    }
  },
  mounted() {
    // 清空富文本默认值
    docuemnt.getElementsByClassName('.ql-toolbar')[0].placeholder = ''
    // 遍历添加提示
    for (let item of this.tooltips) {
      let tip = document.querySelector('.ql-toolbar ' + item.choice)
      if (!tip) {
        continue
      }
      tip.setAttribute('title', item.title)
    }
  },
}
</script>
View Code
复制代码

修改后效果

 成功则跳过之后内容

 

如果不生效,需要检查标签之间的关系是否正确

 

 浏览器F12,鼠标左键点击最左侧第一个带鼠标箭头的图标

 在页面中点击富文本外层元素

看到元素名称 <div class="ql-toolbar ql-snow"...

执行

document.querySelector(".ql-toolbar")

获取元素正常

 再次点击带鼠标箭头的图标,点击页面内工具栏B按钮,可以看到class为.ql-bold

保证元素获取都是正确的,检查完代码再次尝试吧。

js拼接时,注意querySelector时,外层class与内层class之间的空格

 

posted on   le.li  阅读(41)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示