wangeditor中添加超链接校验

在编辑器中添加链接必须添加以http://格式开头的地址才能跳转到外链地址

如果不加,就会带入本域名地址,所以在需要设置一下:

this.editor = new E('#editor');

this.editor.customConfig.showLinkImg = false;
this.editor.customConfig.linkCheck = function(text, link) {
	if (link != "") {
	    var reg = /(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?/;
		if (!reg.test(link)) {
			return '请输入正确的网址(例如 http://baidu.com)'
		}else{
		    return true
		}
        }
}

this.editor.create(); //创建编辑器

参考:https://www.kancloud.cn/wangfupeng/wangeditor3/415032

发布了94 篇原创文章 · 获赞 42 · 访问量 13万+

猜你喜欢

转载自blog.csdn.net/qq_29483485/article/details/100933901