[英]Calling Editinplace jquery plugin on a function and not on click
我正在使用 jQuery editinPlace 插件,進行就地編輯的默認方式是使用選擇器上的單擊事件,但我嘗試執行的方式是通過上下文菜單調用 function“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 )
在第一個 function 聲明$.fn.editInPlace
Line#26 中,更改以下行:
new InlineEditor(settings, dom).init();
進入 >
dom.theEditor = new InlineEditor(settings, dom);
dom.theEditor.init();
dom.data("theEditor", dom.theEditor);
現在在上下文菜單 function 的點擊事件中,調用它 >
$("#myContextMenuElement").live("click", function (e) {
//your other code
rename(e); //you need to pass the event argument to it now
});
確保將“e”傳遞給它。
並在重命名 function >
function rename(e) {
$("#myElementToEditInPlace").data("theEditor").openEditor(e);
}
奇跡般有效 !
編輯:
為確保您不允許用戶通過單擊 para 本身來激活編輯器 > 使用此代碼:
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;
}
};
並在您的初始化中添加代表>
$('.context').editInPlace({
callback: function(idOfEditor) {
var renameUrl = "http://www.google.com/"+tablerowId+"/"+enteredText+"";
return enteredText;
},
delegate: del
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.