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

如何在CKEditor 5中用正则验证链接?绑定事件遇报错

CKEditor 5链接验证及事件绑定问题

背景

我正在开发一款基于CKEditor的CMS,需要通过正则表达式验证链接有效性。找到一个7年前的同类问题解决方案,但尝试后出现报错。不确定是CKEditor版本更新导致的兼容问题,还是我的配置有误——目前我采用源码构建CKEditor 5的方式,目的是深入理解编辑器的工作机制。

当前编辑器配置代码

ClassicEditor
    .create( document.querySelector( '#editor' ), {
        plugins: [ Link, Essentials, Paragraph, Bold, Italic, Alignment  ],
        toolbar: [ 'bold', 'italic', 'link', 'alignment' ],
        link: {
            decorators: {
                openInNewTab: {
                    mode: 'manual',
                    label: 'Open in a new tab',
                    defaultValue: true,         // 该选项默认选中
                    attributes: {
                        target: '_blank',
                        rel: 'noopener noreferrer'
                    }
                }
            }
        }
    } )
    .then( editor => {
        console.log( 'Editor was initialized', editor );
    } )
    .catch( error => {
        console.error( error.stack );
    } );

事件绑定尝试及报错

为实现链接验证,我尝试绑定dialogDefinition事件,但遇到以下问题:

  • 使用代码:
ClassicEditor.on('dialogDefinition', function (ev) {
    console.log("Test")
});

报错信息:"ClassicEditor.on is not a function"

  • 改用代码:
CKEDITOR.on('dialogDefinition', function (ev) {
    console.log("Test")
});

报错信息:CKEDITOR is not defined


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.20 11:57:21