Javascript 将变量作为类传递给Jquery的参数

Javascript 将变量作为类传递给Jquery的参数,javascript,jquery,html,Javascript,Jquery,Html,如果我做这样的东西: $('.reporte, .maquinaria').on('change', function () { var clase = $(this).hasClass('reporte') ? "reporte" : "maquinaria"; var item = {}; $(clase).each(function () { item[$(this).attr('id')] = $(this).val(); });

如果我做这样的东西:

$('.reporte, .maquinaria').on('change', function () {
    var clase = $(this).hasClass('reporte') ? "reporte" : "maquinaria";
    var item = {};

    $(clase).each(function () {
        item[$(this).attr('id')] = $(this).val();
    });
    json[clase].splice(0, 1);
    json[clase].push({
        item
    });
    console.log(json[clase])
});

它起作用了。但是我想用我已经有的var类通过这个类。

这个类需要一个。在选择器的前面。$。+克拉斯

谢谢,成功了!我是Jquey的新手,我不知道我能做出这样的事情
$('.clase').each(function () {
    item[$(this).attr('id')] = $(this).val();
});