javascript - 将变量传递给 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 类来通过课程。
解决方案
该类.
在选择器之前需要一个。$("." + clase)
推荐阅读
- android-studio - javax.net.ssl.SSLException:无法解析 urlconnection.connect() 中的 TLS 数据包标头
- c# - EF Core 多对多关系上的 LINQ 查询
- python - Tensorflow Hub 嵌入模型位置参数不受限制
- mongodb - 更新主副本时 MongoDB 副本集丢失数据库(Kubernetes + Bitnami Helm Chart)
- django - 如何在 Wix 网站上嵌入 Django 应用程序?
- arrays - 如何在swagger yaml中声明数组中的数组
- pdf - 有没有办法在pdf链接对面的边距中打印目标页码
- mercurial - 如何确定是否可以推送到远程存储库?
- debugging - ptrace:正确终止多线程跟踪,而不终止跟踪器
- javascript - 输入时显示按钮反应