Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/86.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_Events_Search_Parameters - Fatal编程技术网

Javascript jQuery取消绑定已选中单选按钮上的单击事件

Javascript jQuery取消绑定已选中单选按钮上的单击事件,javascript,jquery,events,search,parameters,Javascript,Jquery,Events,Search,Parameters,我正在尝试创建一些参数化过滤器,但我不想在已选择单选按钮过滤器时调用进行搜索AJAX调用的函数 $('#contentType input:enabled').bind('click', function(e){ var $this = $(this), $type = this.type, $id = this.id; if ($type === 'radio') { if ($id === 'allContent'){

我正在尝试创建一些参数化过滤器,但我不想在已选择单选按钮过滤器时调用进行搜索AJAX调用的函数

$('#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将有助于:

基本上,如果所有内容类型都已选中,并且在选中时单击,则不应调用searchAjax。它当前调用该函数


如果未选中并单击它,则其行为应与现在相同(禁用同级单选按钮并取消选中所有相关复选框)。

在处理程序顶部添加:

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

如果当前选择了单选按钮,则事件处理程序将返回且不执行函数的其余部分。

此处找到的答案:它有效,但在组中的所有单选按钮上返回false。我试图将其与jQuery的
.on('click',function(){})
方法结合使用。我错过什么了吗?
$('#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);
            }               
        }           
    }   
});