[英]Pass a variable to Jquery's parameter as if it was a class
$('.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])
});
if I make something like this: 如果我做这样的事情:
$('.clase').each(function () {
item[$(this).attr('id')] = $(this).val();
});
it works. 有用。 But I want to pass the class with the var clase that I already have.
但是我想通过我已经拥有的var clase来传递类。
The class needs a .
上课需要一个
.
before it in the selector. 在选择器之前。
$("." + clase)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.