Skip to main content
 首页 » 编程设计

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

2026年07月31日3mfrbuaa

我正在使用 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 
    });