开发者

jQuery synchronization of functions (only works with alert)

开发者 https://www.devze.com 2023-01-08 10:39 出处:网络
Here I construct an array: var optionTexts = []; $(\'#stripeMeSubSubCat tr\').each(function(){ if ($(this).find(\'input:checkbox.subsubcat_chkclass:not(:checked)\').length == 0)

Here I construct an array:

var optionTexts = [];
    $('#stripeMeSubSubCat tr').each(function(){
        if ($(this).find('input:checkbox.subsubcat_chkclass:not(:checked)').length == 0)
            {
                subsubrow_cat_id_no = parseInt($(this).closest("tr").attr("id"));               
                optionTexts.push(parseInt(subsubrow_cat_id_no));
            };          
    });

The code below only works whenever the alert is enabled. I have read that this might be due to a synchronization issue. Is there a solution towards the code below? Thank you.

$('#stripeMeSubSubCat tr').each(function(){                                      
        myindex = parseInt($.trim($(this).closest("tr").attr("id")));

        if (jQuery.inArray(myindex, optionTexts) == -1) {
             var equal="FALSE";
        }else{
             var equal="TRUE";
            $("#stripeMeSubSubCat tr开发者_运维百科[id='" + myindex + "'] input").attr('checked', true);       
        };  

        //alert(equal);
});


What do you mean by "only works whenever the alert is enabled"? You need to describe the difference in behavior in both cases.

Your code has no asynchronous calls, so there shouldn't be synchronization issue. However, you seem to be using an integer as a DOM element id. This isn't allowed.


You probably need to wait for the DOM to load. Try wrapping this code in:

$(function(){
  // put code here
});
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号