我正在编辑链接插件,以允许员工选择内部内容的链接。
我已成功向链接插件对话框添加另一个选项卡,其中包含带有 onKeyup
事件的文本输入。这个想法是,当他们输入时,它会在下面列出结果,他们可以在其中选择他们想要的链接。选择后,我将使用 url 和协议(protocol)更新信息选项卡。
这是现有链接插件中的我的代码部分:
....
....
//Should update info tab with value
function AddLink(txtLink)
{
var dialog = this.getDialog();
dialog.setValueOf('info', 'url', txtLink);
dialog.setValueOf('info', 'protocol', '');
}
//called when the user types in the search box. currently just uses text for basic testing
var searchBoxChanged = function ()
{
var dialog = this.getDialog();
var href = $(this).attr('href');
var txt = dialog.getValueOf('article', 'searchWords');
$('#searchResults').html("<a href=\"JavaScript:AddLink('/Article/View/" + txt + "')\">Test Title</a>");
}
....
....
{
//Adds extra tab to the link plugin for custom link searching
id: 'article',
label: linkLang.article,
title: linkLang.article,
elements:
[
{
type: 'text',
id: 'searchWords',
label: linkLang.articleSearch,
style: 'height:40px',
size: 29,
onKeyUp: searchBoxChanged
},
{
type: 'html',
html: '<div id="searchResults">Please start tying to get results</div>'
}
]
}
....
....
目前我只是使用文本框中的一些基本静态数据。页面上创建的链接正常,但是单击它时出现错误:
CRIPT5009: 'AddLink' is undefined
任何人都可以阐明我哪里出了问题吗?
最佳答案
根据我的经验,[“x”未定义]错误通常意味着存在语法错误,或者通常是函数中的某些内容与您认为的不同。
可能,this.getDialog() 脱离了上下文,因此它不会返回任何内容。那么,dialog.setValueOf() 将不起作用。
关于javascript - 自定义CKEditor链接插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5698247/