jquery – .is(‘:checked’)总是返回true

HTML

<table id="list">
   <tr>
      <td><input type="checkBox" checked="true"></td>
      <td>...</td>
   </tr>
   <tr>
      <td><input type="checkBox" checked="true"></td>
      ...
   </tr>
   ...
</table>

JS:

$('#list tr').each(function(){
   console.log(
        $(this).find('input[type="checkBox"]').is(':checked')
   );    
});

问题:上面的日志语句总是返回true.每个tr都包含一些数据,我想使用这些数据执行操作.但是用户可以取消选择某些实体,在这种情况下这是不可能的,因为is(‘:checked’)总是返回true,即使取消选中/取消选中该条目也是如此.

任何想法如何解决这一问题?

解决方法

您的’checked’属性的值为true,因此即使选中< input type =“checkBox”/>也会返回true也将被检查.

我用你的代码创建了一个demo,还有其他功能来检索.is(“:checked”),因为它的属性发生了变化.

$("input").change(function() {
    console.log($(this).is(':checked'));
});

显示了变化.你的问题必须在其他地方.

相关文章

页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
jQuery实时显示日期、时间 html: &lt;span id=&quot...
jQuery 添加水印 &lt;script src=&quot;../../../.....
中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
1. 用Response.Write方法 代码如下: Response.Write(&q...
Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...