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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章