Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 从复选框数据创建变量名_Jquery - Fatal编程技术网

Jquery 从复选框数据创建变量名

Jquery 从复选框数据创建变量名,jquery,Jquery,有什么帮助吗?如果需要全局变量,请使用: $('.setupcheck').each(function(){ if ($(this).is(':checked')){ variable named $(this).data('x') = 1; } else{ variable named $(this).data('x') = 0; } } }); 现在检查console.log(xpslider) 或者,如果您想将它们单独存储,

有什么帮助吗?

如果需要全局变量,请使用:

$('.setupcheck').each(function(){
    if ($(this).is(':checked')){
        variable named $(this).data('x') = 1;
    }
    else{
        variable named $(this).data('x') = 0;
    }
}
});
现在检查
console.log(xpslider)

或者,如果您想将它们单独存储,则:

var storeObj = window;

$('.setupcheck').each(function(){
    if ($(this).is(':checked')){
        storeObj[$(this).data('x')] = 1;
    }
    else{
        storeObj[$(this).data('x')] = 0;
    }
});

并用作
console.log(storeObj.xpslider)

如果需要全局变量,请使用:

$('.setupcheck').each(function(){
    if ($(this).is(':checked')){
        variable named $(this).data('x') = 1;
    }
    else{
        variable named $(this).data('x') = 0;
    }
}
});
现在检查
console.log(xpslider)

或者,如果您想将它们单独存储,则:

var storeObj = window;

$('.setupcheck').each(function(){
    if ($(this).is(':checked')){
        storeObj[$(this).data('x')] = 1;
    }
    else{
        storeObj[$(this).data('x')] = 0;
    }
});
并用作
console.log(storeObj.xpslider)

名为$(this).data('x')=1的[this]()。
变量可能重复???名为$(this).data('x')=1的[this]()。
变量可能重复???