我可以这样做:
$('.box').delegate('.edit', 'click', function(edit_event){
...
var input = $('input', this);
input.focus().bind('blur keypress', function(event){
// here disable the first .edit event (don't allow click on that element)?
});
});
如果在第二个事件(以及AJAX调用完成时)满足某些条件,则会再次启用该事件。
答案 0 :(得分:2)
由于您使用的是基于选择器的delegate()
[docs]方法,因此您只需将一个类添加到当前.edit
中,该类将其从选择器中排除。
// only invoke if it has "edit" class and not "disable" class
$('#box').delegate('.edit:not(.disable)', 'click', function (edit_event) {
// add the class to this edit element to disable it
var edit = $(this).addClass('disable');
var input = $('input', this);
input.focus().bind('blur keypress', function (event) {
// here disable the first .edit event (don't allow click on that element)?
// after some work, remove the class to re-enable the click
edit.removeClass('disable');
});
});
我使用了not-selector
[docs],因此在移除click
类之前,disable
事件不会触发。