ueditor php 网络链接错误,ueditor使用editor.execCommand( 'link', {})插入链接无效的问题...
介紹
因?yàn)轫?xiàng)目需要,所以要在百度富文本編輯器ueditor上二次開發(fā),有一個(gè)就是在富文本中插入鏈接的功能;
官方文檔如下:
execCommand(String cmd, Object options)
執(zhí)行當(dāng)前命令
參數(shù)列表
參數(shù)名
類型
描述
cmd
String
命令字符串
options
Object
設(shè)置自定義屬性,例如:url、title、target
示例
editor.execCommand( 'link', '{
url:'ueditor.baidu.com',
title:'ueditor',
target:'_blank'
}' );
這里首先要糾正下,這里官方的代碼演示是錯(cuò)誤的,第二個(gè)參數(shù)應(yīng)該是一個(gè)對象,而不是字符串,所以,正確用法應(yīng)該是
editor.execCommand( 'link', {
url:'ueditor.baidu.com',
title:'ueditor',
target:'_blank'
});
復(fù)現(xiàn)問題
當(dāng)插入鏈接(調(diào)用此方法)后,文本框沒有反應(yīng);
然后我們嘗試著去檢查富文本編輯框html代碼,會(huì)發(fā)現(xiàn):
鏈接加上了,但沒有文字,原來title字段是a 標(biāo)簽的title屬性。。。然而官方文檔也沒有詳細(xì)說明;
解決辦法
通過斷點(diǎn)查找,找到了 ueditor \ utf8-php \ dialogs \ link的link.html文件,如下有這么一段代碼:
function handleDialogOk(){
var href =$G('href').value.replace(/^\s+|\s+$/g, '');
if(href){
if(!hrefStartWith(href,["http","/","ftp://",'#'])) {
href = "http://" + href;
}
var obj = {
'href' : href,
'target' : $G("target").checked ? "_blank" : '_self',
'title' : $G("title").value.replace(/^\s+|\s+$/g, ''),
'_href':href
};
//修改鏈接內(nèi)容的情況太特殊了,所以先做到這里了
//todo:情況多的時(shí)候,做到command里
if(orgText && text.value != orgText){
link[browser.ie ? 'innerText' : 'textContent'] = obj.textValue = text.value;
range.selectNode(link).select()
}
if(range.collapsed){
obj.textValue = text.value;
}
editor.execCommand('link',utils.clearEmptyAttrs(obj) );
dialog.close();
}
}
結(jié)果測試,是obj.textValue起到了關(guān)鍵作用,所以,可以改為
editor.execCommand( 'link', {
url:'ueditor.baidu.com',
title:'ueditor',
target:'_blank',
textValue:'ueditor'
});
SUCCESS
總結(jié)
以上是生活随笔為你收集整理的ueditor php 网络链接错误,ueditor使用editor.execCommand( 'link', {})插入链接无效的问题...的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 智慧城市这份试卷 国外城市怎么答题?
- 下一篇: php 循环多条件,怎么循环带条件的数组