5

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

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

1 回答 1

1

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

在第一个函数声明$.fn.editInPlaceLine#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);
}

奇迹般有效 !

编辑:

为确保您不允许用户通过单击 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
    });
于 2011-05-02T10:54:04.397 回答