Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/383.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~在跟随它之前调整href_Javascript_Jquery_Dom - Fatal编程技术网

Javascript jQuery~在跟随它之前调整href

Javascript jQuery~在跟随它之前调整href,javascript,jquery,dom,Javascript,Jquery,Dom,由于遗留代码的原因,我有一个带有一系列复选框的链接,当用户单击复选框时,复选框的值将作为逗号删除列表附加到href 问题是,现在我正在更新代码,我发现href的跟随速度比href的调整速度快,因此列表被排除在外 我尝试过使用preventDefault,这很好,但我不知道在更改href以包含所选值后如何继续默认操作 我还应该提到,将其更改为常规格式是不可行的,因为在提交后,灯箱中设置了一个附加选项。别问我为什么,这是我书中的疯狂 到目前为止,我必须 $(function(){ $('#c

由于遗留代码的原因,我有一个带有一系列复选框的链接,当用户单击复选框时,复选框的值将作为逗号删除列表附加到href

问题是,现在我正在更新代码,我发现href的跟随速度比href的调整速度快,因此列表被排除在外

我尝试过使用preventDefault,这很好,但我不知道在更改href以包含所选值后如何继续默认操作

我还应该提到,将其更改为常规格式是不可行的,因为在提交后,灯箱中设置了一个附加选项。别问我为什么,这是我书中的疯狂

到目前为止,我必须

$(function(){
    $('#cnt-area form table tbody').dragCheck();

    // I just split up the .each and .click to see if it mattered, which it doesnt
    $('.multi_assign_link').each(function(){
        $(this).click(function(e){

            e.preventDefault();
            var href = $(this).attr('href');

            $('#cnt-area form input:checkbox').each(function(){
                if($(this).attr('checked')){
                    if(href.search(','+$(this).val()) == -1){
                        href += ','+$(this).val();
                    }
                }else{
                    var s = ','+$(this).val();
                    s.toString();
                    href = href.replace(s, '');
                }
            });
            $(this).attr('href',href);
            // Continue to follow the link
            // Faking a user click here with $(this).click(); obviously throws a loop!
        });
    });
});

只需将位置设置为调整后的href值,并从处理程序返回false,以避免获取原始链接

$(function(){ 
    $('#cnt-area form table tbody').dragCheck(); 

    // I just split up the .each and .click to see if it mattered, which it doesnt 
    $('.multi_assign_link').each(function(){ 
        $(this).click(function(e){ 

            var href = $(this).attr('href'); 

            $('#cnt-area form input:checkbox').each(function(){ 
                if($(this).attr('checked')){ 
                    if(href.search(','+$(this).val()) == -1){ 
                        href += ','+$(this).val(); 
                    } 
                }else{ 
                    var s = ','+$(this).val(); 
                    s.toString(); 
                    href = href.replace(s, ''); 
                } 
            }); 
            location.href = href;
            return false;
        }); 
    }); 
});

像location.href=href这样简单的东西就足够了吗?不,因为我在提交时有一个模式光窗口。我不能使用它,因为我需要在点击链接后打开一个thickbox。经过反思,我将一起摆脱这个恼人的thickbox!