开发者

Problem in removing and showing row in jquery

i am having a problem in my code of hiding and displaying开发者_如何学Python the row again but it isn't working. when i comment the code of 2nd loop then it woks perfectly fine but when i add 2nd loop then again trouble. Here is my code.

<script>


    $("#btnClick").click(function(){

        $("form input[type=checkbox]:not(:checked)").each(
        function(){
                var checkBoxID = $(this).attr('id');

                //alert("checkBoxID"+" "+checkBoxID);
                $("table td").each(function(){

                    if(checkBoxID==$(this).attr('id')){
                    //alert($(this).attr('id'));
                        $(this).hide();
                    }
                });
        });

        $("form input[type=checkbox][checked]").each(
        function(){
                var checkBoxID = $(this).attr('id');

                //alert("checkBoxID"+" "+checkBoxID);
                $("table td").each(function(){

                    if(checkBoxID==$(this).attr('id')){
                    //alert($(this).attr('id'));
                        $(this).show();
                    }
                });
        });
    });

</script>

Thanks in Advance.


Replace this

$("form input[type=checkbox][checked]").each(

with

$("form input[type=checkbox]:checked").each(


What is actually happening is that in the $.each loops, when you refer to $(this) it is actually examining the td, since you are using $("table td").

Actually... looking a second time it seems that you are probably using the same ID for the checkbox and the td to hide it?

The Problem: replace the initial each function with this:

$("form input[type=checkbox]").not(":checked").each(//..

.

$("#btnClick").click( function(){ 
   $("form input[type=checkbox]:not(:checked)").each( function(){ 
     var checkBoxID = $(this).attr('id'); 
     //alert("checkBoxID"+" "+checkBoxID); 
     $("table td").each(function(){ 
        if(checkBoxID==$(this).attr('id')){ 
          //alert($(this).attr('id')); 
          $(this).hide(); 
        } 
     }); 
   }); 
   $("form input[type=checkbox][checked]").each( function(){ 
      var checkBoxID = $(this).attr('id'); 
      //alert("checkBoxID"+" "+checkBoxID); 
      $("table td").each(function(){ 
         if(checkBoxID==$(this).attr('id')){ 
            //alert($(this).attr('id')); 
            $(this).show(); 
          }  
      }); 
    }); 
}); 
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜