jQuery选择(每个)所有选中的复选框? [英] jquery select (each) all checked checkboxes?

查看:45
本文介绍了jQuery选择(每个)所有选中的复选框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以提供以下帮助,它不会返回任何选中的复选框. 我做错什么了吗?

Can anyone help with the following, it doesn't return any checked checkboxes.. Am i doing somethign wrong?

我有

$("input[type=checkbox][checked] .type-element").each(
    function(index) {
        alert('checked' + index);
    }
);

这是我html的一部分(我有很多都属于类型容器)

here is part of my html ( i have a number of them all as type-container)

     <div id="type-1" class="type-container">
         <div class="type-description">
             test
         </div>
         <input id="11" class="type-element" type="checkbox"/>
     </div>

推荐答案

只需:

$(":checked")...

对于选中的复选框.另外,在".type-element"之前的表达式中还有一个多余的空间.如果要确保选中的复选框具有该类,请使用:

for checked checkboxes. Also you have an extraneous space in your expression before ".type-element". If you want to make sure the checked checkboxes have that class use:

$(":checked.type-element")...

不是":checked .type-element"(请注意空格).

所以最终结果是:

$(":checked.type-element").each(
  function(index) {
    alert('checked' + index);
  }
);

这篇关于jQuery选择(每个)所有选中的复选框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆