首页 > 解决方案 > 将变量传递给 Jquery 的参数,就好像它是一个类一样

问题描述

$('.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])
});

如果我做这样的事情:

$('.clase').each(function () {
    item[$(this).attr('id')] = $(this).val();
});

有用。但是我想通过我已经拥有的 var 类来通过课程。

标签: javascriptjqueryhtml

解决方案


该类.在选择器之前需要一个。$("." + clase)


推荐阅读