2013-01-22 37 views
0

我正在使用以下与地址选择器。jquery撤消函数绑定

HTML

<form> 
<input id="searchByLoc" type='checkbox' > 
<input id="searchQuery" type='text' > 
<input type="submit' value="search"> 
</form> 

JQuery的:

$('#searchByLoc:checkbox ').live('change', function(){ 
    if($(this).is(':checked')){ 
     var addresspicker=$(this).addresspicker();//alert('checked'); 
    } else { 
     //I want to un initialize the addresspicker() on the input field 
     var addresspicker=die($(this).addresspicker());//alert('un-checked'); 
    } 
}); 

我遇到一些麻烦else部分的上方。如果取消选中该复选框,如何停止初始化以避免建议位置?

+1

我很困惑,不只是删除ELSE ? –

+0

嗯,没有。 bcz输入字段旨在用于按名称和位置进行搜索。所以,如果搜索完成位置,然后搜索名称即将完成,我想没有位置建议。 – aVC

+0

我不认为解绑更改事件是你想要的,但是如果它被选中或者不在你的'adresspicker()'中处理...... –

回答

2

使用jquery的unbind()函数。它将删除该事件。 jquery bind

你可以看到这个帖子也最好使用best way to remove events

下面的jQuery 1.7

$('#yourDomElement').unbind('click'); 

jQuery的1.7+

$('#yourDomElement').off('click'); 
+0

注意,如果使用jQuery 1.7+,建议您使用'on()'/ off()'而不是'live()'''unbind()'。 –

+0

他会解绑什么? –

+0

我应该解除什么?我试过addresspicker.unbind();不起作用 – aVC