搞了一天,都没有搞出来,求教!!!
问题描述:有多个checkbox,其中的一些拥有相同的class名(这些checkbox可能不只一个class),如何判断这些checkbox是否被选中?
谢谢!

解决方案 »

  1.   

    我实在不懂你到底指的是哪些.是全体CHECKBOX还是有相同CLASS的.
    你说的意思大概是根据样式有不同的分组,但你不管是哪些分组,只是想知道它们是否被选中.
    但是,是知道每个个体是否被选中,还是整体被选中呢?还是不清楚你具体想怎样.
    $("input[type=checkbox]").each(function(){alert(this.checked});
      

  2.   

    是我没有描述清楚。
    我这样说吧:比如,有10个checkbox,所有的checkbox都有一个class名叫class_1。在这10个checkbox中,又进行了区分,有5个class名叫class_2(也就是说,这5个除了有class_1这个class名以外,还有一个class_2的class名),目前,class名为class_2的这5个checkbox,其中有一些可能被选中了,我要怎么样才能得到被选中的这些checkbox?
    如果使用:$("input[type=checkbox]").each(function(){alert(this.checked});得到的是所有的checkbox的。
    希望我已经说清楚了。谢谢你!
      

  3.   

    哎,这个表达如果你想知道10个checkbox(class名叫class_1)的情况:$("input[type=checkbox].class_1")
    如果你想知道5个checkbox(class包含class_2)的情况:$("input[type=checkbox].class_2")
      

  4.   

    呵呵,直接说如何选择CLASS含有两个或者多个样式名称的对象就行了.
    <input type="checkbox" class="class_1">
    <input type="checkbox" class="class_1" checked id="theforever_noClass2">
    <input type="checkbox" class="class_1 class_2">
    <input type="checkbox" class="class_1 class_2" checked id="theforever_knight">
    <input type="checkbox" class="class_1 class_2" checked id="theforever_csdn">
    <input type="checkbox" class="class_1 class_2">
    <input type="checkbox" class="class_1 class_2">
    <input type="checkbox" class="class_1">
    <input type="checkbox" class="class_1">
    <input type="checkbox" class="class_1">
    <script>
    $(function(){ 
    $("input.class_1.class_2:checked").each(function(){alert(this.id)});
    //虽然上面ID为"theforever_noClass2"的也是选中状态,但不会把它也取过来
    });
    </script>