如何删除$(document).on click事件? [英] How to remove $(document).on click event?
本文介绍了如何删除$(document).on click事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是添加事件的代码
$(document).on({
click: function() {
$(this).hide();
$('#form_name').removeClass('hide');
$('#form_template_name')
.attr('placeholder', $(this).text())
.focus();
}
}, '.form-template-name');
在某些情况下,我不希望触发此事件.所以我尝试的是
For some conditions i dont want this event to trigger. So what I tried is
$('.form-template-name').off();
$('.form-template-name').unbind();
但是似乎没有任何效果.我有想念什么吗?
But nothing seems to work. Did I miss anything ?
推荐答案
您需要传递事件以取消绑定到.off(),还请参见使用命名空间事件名称
You need to pass the event to unbind to .off(), also see the use of namepsaced event names
$(document).on({
'click.myevent': function () {
$(this).hide();
$('#form_name').removeClass('hide');
$('#form_template_name')
.attr('placeholder', $(this).text())
.focus();
}
}, '.form-template-name');
和
$(document).off('click.myevent', '.form-template-name');
演示:小提琴
这篇关于如何删除$(document).on click事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文