未在Jquery即兴更新复选框值

未在Jquery即兴更新复选框值,jquery,checkbox,Jquery,Checkbox,我有一个复选框列表,在jquery即兴中有一些测试框。在保存更新后的值时,我可以看到textbox的更新数据,但无法看到checkbox的更新数据 这是代码。请检查并指导我 更新复选框值的代码: $("input[type='checkbox']").each(function(){ if($(this).attr('checked')!=undefined){ f.completion=true; }else{ f.completion=fals

我有一个复选框列表,在jquery即兴中有一些测试框。在保存更新后的值时,我可以看到textbox的更新数据,但无法看到checkbox的更新数据

这是代码。请检查并指导我

更新复选框值的代码:

$("input[type='checkbox']").each(function(){
    if($(this).attr('checked')!=undefined){
        f.completion=true;
    }else{
        f.completion=false;
    }
});

您应该引用未定义的:

$("input[type='checkbox']").each(function(){
    if($(this).attr('checked')!="undefined"){
        f.completion=true;
    }else{
        f.completion=false;
    }
});
或者最好这样使用:

if($(this).attr('checked')!=true){
if($(this).attr('checked')){
    if(this.checked!=true){
或者像这样:

if($(this).attr('checked')!=true){
if($(this).attr('checked')){
    if(this.checked!=true){
或者像这样使用更好:

if($(this).attr('checked')!=true){
if($(this).attr('checked')){
    if(this.checked!=true){
您也可以使用prop()方法而不是attr()方法。

使用like

if
语句中使用
.prop('checked')
,而不是
.attr('checked')
,并检查
true
false
,还可以查看下面的代码段,我总是使用它来动态生成复选框

// check all and unchecked all functions for a group of checkboxes 
$(".group1Checkbox").click(function () {
"use strict";
$('.group1Checkbox').prop('checked', true).checkboxradio('refresh');
$('.group1Checkbox').prop('checked', false).checkboxradio('refresh');
});

为什么不
this.checked
?是的,也有,但只在jquery中标记。只需使用
this.checked
,它将告诉您是否选中复选框。每当我取消选中我的复选框时,该值不会传递到我的spring控制器。