Kendo 编辑器动态链接 onClick 功能不起作用
我有一个自定义工具栏,它在剑道编辑器中插入一个链接。我试图在该链接中放置一个 onClick 函数,但是当单击动态插入的链接时,它说函数未定义。我还尝试过在该链接上放置一个类,并对该类有一个单击功能,但它没有被击中。
任何帮助将不胜感激。
$("toolbarSubmitBtn").("click", function () {
var value = $("toolbarInput").val();
var $html = '<a onClick="myFunction()"> Click to show alert </a>';
//var $html = '<a class="functioncall"> Click to show alert </a>';
var $empty = $("<div>").append($html)
$("#editor").data("kendoEditor").paste($empty.html());
});
类调用
$(document).on("click", ".functioncall", function () {
alert("function called from class");
});
函数调用
function myFunction() {
alert("function called by click");
}
I have a custom toolbar which inserts a link in kendo editor. I am trying to put a onClick function in that link but when the dynamically inserted link is clicked it says function is not defined. I also tried it by putting a class on that link and have a click function to that class but it does not get hit.
Any help would be much appreciated.
$("toolbarSubmitBtn").("click", function () {
var value = $("toolbarInput").val();
var $html = '<a onClick="myFunction()"> Click to show alert </a>';
//var $html = '<a class="functioncall"> Click to show alert </a>';
var $empty = $("<div>").append($html)
$("#editor").data("kendoEditor").paste($empty.html());
});
Class Call
$(document).on("click", ".functioncall", function () {
alert("function called from class");
});
Function Call
function myFunction() {
alert("function called by click");
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为问题在于 Kendo 编辑器将正文内容放在 IFRAME 中,而您的“myFunction”不在该 IFRAME 中。尝试将 onClick 设置为
(可选)在插入的链接上设置
contenteditable="false"
以防止用户编辑链接文本。这是一个 DEMO
I believe the issue is that the Kendo Editor puts the body content within an IFRAME and your "myFunction" is not within that IFRAME. Try setting the onClick to
Optionally, set
contenteditable="false"
on your inserted link to prevent user editing the link text.Here is a DEMO