使Jeditable处理新元素 [英] Making Jeditable working on new elements

查看:101
本文介绍了使Jeditable处理新元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使可编辑适用于使用

I'm trying to make Jeditable works on new elements created using this jquery file tree.

在文件夹或文件上单击鼠标右键,将显示一个上下文菜单,单击上下文菜单上的重命名"项目后,我要激活Jeditable.

On right click on a folder or file a context menu is shown and after clicking "Rename" item on the context menu i want to activate Jeditable.

我正在使用此上下文菜单和代码:

I'm using this context menu and this code:

$(document).ready( function() {
$('#filetree').fileTree({
    root: '../../../',
    script: './connectors/jqueryFileTree.php',
    expandSpeed: 1000,
    collapseSpeed: 1000,
    multiFolder: true
}, function(file) {
    alert(file);
});

$.contextMenu({
    selector: 'ul.jqueryFileTree > li', 
    callback: function(key, options) {
        var m = "clicked: " + key;
        window.console && console.log(m);
        if(key == 'rename'){
            $('#1').trigger("edit1");
            }
    },
    items: {
        "rename": {name: "Rename", icon: "edit", accesskey: "r"},
        "cut": {name: "Cut", icon: "cut", accesskey: "c"},
        // first unused character is taken (here: o)
        "copy": {name: "Copy", icon: "copy", accesskey: "c o p y"},
        // words are truncated to their first letter (here: p)
        "paste": {name: "Paste", icon: "paste", accesskey: "cool paste"},
        "delete": {name: "Delete", icon: "delete"},
    }
});

/* Bind Jeditable instances to "edit" event. */


$("#1").editable("http://www.example.com/save.php", {
 event: 'edit1',

 });
});

});

但是不起作用,我已经在网络上阅读(此处)我应该使用.live(.on()还可以吗?因为我使用的是jquery 1.7.1),但我不知道为什么,你能帮我吗?

But doesn't work, i've read on the web (here)that i should use .live (.on() is ok? since i'm using jquery 1.7.1) but i don't know why, can you help me?

推荐答案

,您可以使用 .on() 代替> .live() ,类似于

you can use .on() in place of .live() which works sort of like the .delegate() method. live is bit expensive as it keep track of the DOM changes and for that it has to iterate where as the .on() or .delegate() simply delagate the event to a higher element like document or the body.

    $('.editableItem').live('click', function(){
        $(this).editable("http://www.example.com/save.php", {
     event: 'edit1',
     });
   });

Why you have to use live?

Why you have to use live?

因为动态插入到DOM中的元素不会自动绑定到事件处理程序,因此您必须使用live,或者在插入元素后,可以使用

Because dynamically inserted elements into the DOM dont get attached to the event handlers automatically for that you have to use live or upon insertion of elements you can manually bind the elements to the event handlers by using .bind()

这是一些有用的问题

jQuery click之间的区别, ,"live","delegate","trigger"和"on"功能(例如)?

Difference between jQuery `click`, `bind`, `live`, `delegate`, `trigger` and `on` functions (with an example)?

jQuery live()与委托()

http://paulirish.com/2010/on-jquery-live/

这篇关于使Jeditable处理新元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆