Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在jQuery中切换在位编辑功能?_Javascript_Jquery_Edit In Place - Fatal编程技术网

Javascript 如何在jQuery中切换在位编辑功能?

Javascript 如何在jQuery中切换在位编辑功能?,javascript,jquery,edit-in-place,Javascript,Jquery,Edit In Place,我一直在玩,我不知道如何正确地禁用它。下面是我到目前为止的代码 我正在使用jQuerytoggle方法初始化和终止链接列表上的插件功能。下面的代码中有一些额外的位可能与我的问题无关,但我把它们留在那里以防万一 问题是,下面的代码在前两次单击时(即,第一次单击-启用editInPlace插件,第二次单击-禁用它)与我预期的一样工作,但是它不会在第三次单击时重新启用在位编辑功能 你知道为什么吗 (shoppingList.editButton).toggle(function() {

我一直在玩,我不知道如何正确地禁用它。下面是我到目前为止的代码

我正在使用jQuery
toggle
方法初始化和终止链接列表上的插件功能。下面的代码中有一些额外的位可能与我的问题无关,但我把它们留在那里以防万一

问题是,下面的代码在前两次单击时(即,第一次单击-启用editInPlace插件,第二次单击-禁用它)与我预期的一样工作,但是它不会在第三次单击时重新启用在位编辑功能

你知道为什么吗

(shoppingList.editButton).toggle(function() {
            (shoppingList.editButton).attr('value', 'Finish editing');
            (shoppingList.$ingrLinks).unbind('click', shoppingList.ingredients) // disable some functionality on links
                                     .addClass('inplace-editor') // add class to links I want to be editable
                                     .removeAttr('href') // make links unclickable
                                     .editInPlace({ // editInPlace plugin initialized
                                         url: 'http://localhost:8000/edit-ingredient/',
                                         show_buttons: true
                                     });

        }, function() {
            (shoppingList.editButton).attr('value', 'Edit items');
            (shoppingList.$ingrLinks).bind('click', shoppingList.ingredients) // bring back the functionality previously removed
                                     .removeClass('inplace-editor') // remove the class from links that were editable
                                     .attr('href', '#') // make the links clickable again
                                     .unbind('.editInPlace') // remove editInPlace plugin functionality
                                     ;
        });

传递给toggle的第一个函数在用户每次单击时执行

传递给toggle的第一个函数将在用户每次单击时执行

将链接替换为链接的克隆。使用参数为false的
$.clone()
时,将从克隆中删除所有事件处理程序

第二个功能(保持第一个功能不变):


将链接替换为链接的克隆。使用参数为false的
$.clone()
时,将从克隆中删除所有事件处理程序

第二个功能(保持第一个功能不变):


找到了一个有效的解决方案:

$('input[name="edit-items"]').toggle(function() {
    $(this).attr('value', 'Finish editing');
    (shoppingList.$ingrLinks).unbind('click', shoppingList.ingredients) // disable highlighting items
                             .removeAttr('href');
    $('.editme').editable("enable");
    $('.editme').editable('http://localhost:8000/edit-ingredient/');
}, function() {
    $(this).attr('value', 'Edit item');
    (shoppingList.$ingrLinks).attr('href', '#');
    $('.editme').editable("disable");
    (shoppingList.$ingrLinks).bind('click', shoppingList.ingredients) // re-enable highlighting items

});

找到了一个有效的解决方案:

$('input[name="edit-items"]').toggle(function() {
    $(this).attr('value', 'Finish editing');
    (shoppingList.$ingrLinks).unbind('click', shoppingList.ingredients) // disable highlighting items
                             .removeAttr('href');
    $('.editme').editable("enable");
    $('.editme').editable('http://localhost:8000/edit-ingredient/');
}, function() {
    $(this).attr('value', 'Edit item');
    (shoppingList.$ingrLinks).attr('href', '#');
    $('.editme').editable("disable");
    (shoppingList.$ingrLinks).bind('click', shoppingList.ingredients) // re-enable highlighting items

});

不,第一个函数每次执行偶数次,而不是每次。不,第一个函数每次执行偶数次,而不是每次。