代码如何,为什么总是输出0??
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>无标题页</title>
    <script src="../Scripts/jquery-1.6.1.min.js" type="text/javascript"></script>  
    <script type="text/javascript">
    
    $(function(){
        $("input[type='checkbox']").click(function(){  
            //alert($("input[id^='chk']").size());
            alert($("input[id^='chk'][checked]").size());
            //alert($("input[id^='chk'][checked=true]").size());这句也全是0        });
    });
    
    </script>
</head>
<body>
       <div>
    <input type="checkbox" id="chk1"  value="1" />1<br />
    <input type="checkbox" id="chk2" value="2" />1<br />
    </div>
    </body>
</html>

解决方案 »

  1.   

       
      $(function(){
      $("input[type='checkbox']").click(function(){  
             alert($(this).size())  });
      });
      

  2.   

    发现ie6下没问题,ie8总是0;但是ie8下each遍历时输出$(this).attr("checked"),该项选中时输入为true...可$("input[id^='chk'][checked]").size()仍为0...
      

  3.   

    晕哦,1楼的,我输出有几个checkbox被选中哈...
      

  4.   

    $(":checkbox:checked")
    中间空格要去掉 。
      

  5.   

    $(":checkbox:checked")
    的话...我在一个页面中有好多checkbox哈...这是拿一部分测式的...还加什么属性?
      

  6.   

      $(function(){
      $("input[type='checkbox']").click(function(){  ;
          var count = function(a){
            var c = 0; 
            for(var i = 0 ; i < a.length ; i ++)
            {
                if(a[i].checked) c++
            }
            return c;
          }($("input[type='checkbox']"))
          alert(count)  });
      });
      

  7.   

    就算你用jquery循环检查是免不了的,
    其实jquery里面也是这个原理,只不过封装好的代码,你看不到而已
      

  8.   

    ($("input[id^='chk']:checked")
    这样吧 。id 是chk开头,被选择的 。
    楼上说得对 ,其实都循环了 。
      

  9.   

    哦,那就用each+attr("checked")吧...
    刚用这个,不大会...没研究过源码;