2011-07-12 69 views
0

我正在尝试创建一些参数过滤器,但我不想调用使单选按钮过滤器被选中时搜索AJAX调用的函数。jQuery解除已经选中的单选按钮上的单击事件

$('#contentType input:enabled').bind('click', function(e){ 
    var $this = $(this), 
     $type = this.type, 
     $id = this.id; 
    if ($type === 'radio') { 
     if ($id === 'allContent'){ 
      sFrm.$boxes.attr({'checked': false}); 
      sFrm.$specificRadio.attr({'disabled': true}); 
      searchAjax(); 
      removeFilter(); 
     } 
    } else if ($type === 'checkbox') { 
     if (sFrm.$boxes.filter(':checked').length === 0) { 
      sFrm.$allRadio.trigger('click');   
     } else { 
      var filterConfig = { 
       index: $('.subFilter').index($this), 
       txt: jQuery.trim($this.parent().text()) 
      }     
      sFrm.$allRadio.attr({'checked': false});   
      sFrm.$specificRadio.attr({'disabled': false, 'checked': true}); 
      searchAjax(); 
      if ($this.is(':checked')) { 
       addFilter(filterConfig); 
      } else { 
       removeFilter(filterConfig.index); 
      }    
     }   
    } 
}); 

所以jQuery的上述着眼于集合中的所有启用的输入和当用户点击allContent单选按钮调用searchAjax功能。

当所述单选按钮尚未被选择/检查时,这是正确的。此刻该功能仍然被调用时,按钮被选中,我想停止这种行为,但无法弄清楚如何?

编辑

不知道我正确解释。希望这会的jsfiddle帮助:

http://jsfiddle.net/QsbRp/3/

基本上如果所有内容类型已经被选中,然后检查searchAjax不应该被调用时,被点击。它当前调用该函数。

当它没有被选中并点击时,它应该像现在一样运行(禁用同级单选按钮并取消选中所有关联的复选框)。

+0

答案在这里找到: http://stackoverflow.com/questions/208471/getting-jquery-to-recognise-change-in-ie – RyanP13

回答

1

添加在你的处理器的顶部:

if ($this.is(":checked")) { 
    return; 
} 

的事件处理函数将返回,如果当前选择的单选按钮不执行该功能的其余部分。

+0

可惜,这是行不通的。 – RyanP13

+0

它可以工作,但会在组中的所有单选按钮上返回false。我试图用jQuery的'.on('click',function(){})'方法来使用它。我错过了什么吗? –