日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > php >内容正文

php

ueditor php 网络链接错误,ueditor使用editor.execCommand( 'link', {})插入链接无效的问题...

發(fā)布時(shí)間:2023/12/19 php 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ueditor php 网络链接错误,ueditor使用editor.execCommand( 'link', {})插入链接无效的问题... 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

介紹

因?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)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。