You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何移除insertdatetime splitbutton下拉菜单实现单击插入时间

结论

可以完全移除insertdatetime按钮的下拉菜单部分,实现点击直接插入当前日期时间的需求,以下是具体实现方案(以常用的TinyMCE富文本编辑器为例,其他编辑器逻辑通用):

实现步骤
  • 重写按钮默认行为,丢弃原有下拉触发逻辑,直接绑定插入日期时间的点击事件
  • 可按需通过CSS隐藏按钮自带的下拉箭头UI元素,彻底清除下拉相关的视觉展示
代码示例

编辑器配置代码

tinymce.init({
  selector: '#editor-container', // 替换为你的编辑器挂载节点
  toolbar: 'insertdatetime',
  // 自定义按钮逻辑覆盖默认行为
  setup: (editor) => {
    editor.ui.registry.addButton('insertdatetime', {
      icon: 'insert-time', // 保留按钮原有自带图标
      onAction: () => {
        // 自定义日期时间格式,可根据需求修改格式化规则
        const currentDatetime = new Date().toLocaleString('zh-CN');
        editor.insertContent(currentDatetime);
      }
    })
  }
})

隐藏下拉箭头的CSS代码

/* 需替换为你所用编辑器对应的下拉箭头类名 */
.tox-split-button__chevron {
  display: none !important;
}

内容的提问来源于stack exchange,提问作者user16709371

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.30 02:27:00