gpt4 book ai didi

jquery - 在函数上调用 Editinplace jquery 插件而不是单击

转载 作者:行者123 更新时间:2023-11-30 23:45:11 26 4
gpt4 key购买 nike

我正在使用 jQuery editinPlace 插件,就地编辑的默认方法是在选择器上使用单击事件,但我尝试执行的方法是通过上下文菜单调用函数“rename();”。那么如何阻止点击事件的内联编辑。请分享一些关于如何执行此操作的想法...

$('.context').editInPlace({ 
callback: function(idOfEditor) {
var renameUrl = "http://www.google.com/"+tablerowId+"/"+enteredText+"";
return enteredText;
}
});

最佳答案

打开/jquery.editinplace.js 源文件。 (网络版>http://code.google.com/p/jquery-in-place-editor/source/browse/trunk/lib/jquery.editinplace.js)

在第一个函数声明 $.fn.editInPlace Line#26 中,更改以下行:

new InlineEditor(settings, dom).init();

进入>

dom.theEditor = new InlineEditor(settings, dom);
dom.theEditor.init();
dom.data("theEditor", dom.theEditor);

现在在上下文菜单函数的单击事件中,调用此>

$("#myContextMenuElement").live("click", function (e) {
//your other code
rename(e); //you need to pass the event argument to it now
});

确保将“e”传递到其中。

并在重命名函数中>

function rename(e) { 
$("#myElementToEditInPlace").data("theEditor").openEditor(e);
}

效果非常好!

编辑:

要确保您不允许用户通过单击段落本身来激活编辑器>请使用以下代码:

var myDelegate = { 
shouldOpenEditInPlace: function (a, b, c) {
if (c.target.id != "idOfYourContextElement") { //if the edit was not invoked through the context menu option
return false; //cancel the editor open event
}
return true;
}
};

并在初始化中添加委托(delegate)>

$('.context').editInPlace({ 
callback: function(idOfEditor) {
var renameUrl = "http://www.google.com/"+tablerowId+"/"+enteredText+"";
return enteredText;
},
delegate: del
});

关于jquery - 在函数上调用 Editinplace jquery 插件而不是单击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5840428/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com