根据输入值是否已更改jQuery将其分配给数组

根据输入值是否已更改jQuery将其分配给数组,jquery,input,attributes,onchange,Jquery,Input,Attributes,Onchange,我什么也找不到,但我觉得以前有人问过 我有多个输入: <input id="id1" class="abc" name="tags" "value="test1" /> <input id="id2" class="abc" name="tags" "value="test2" /> 但从一开始,它就不起作用jQuery(this).attr('id')不作为函数存在。我想这不起作用的原因是因为我没有给某个特定的班级打电话,但我不知道。也许我一直盯着代码看得太多了,但它

我什么也找不到,但我觉得以前有人问过

我有多个输入:

<input id="id1" class="abc" name="tags" "value="test1" />
<input id="id2" class="abc" name="tags" "value="test2" />
但从一开始,它就不起作用
jQuery(this).attr('id')
不作为函数存在。我想这不起作用的原因是因为我没有给某个特定的班级打电话,但我不知道。也许我一直盯着代码看得太多了,但它不起作用


错误:
无法将未定义的转换为对象

在您的情况下,“this”指向function(),而不是您可能期望的jQuery('.abc')实例。请参阅以获取有关此的解释

您需要为
ch[id]

jQuery('.abc').change(function () {
  var id = jQuery(this).attr('id');
  var name = jQuery(this).attr('name');
  var value = jQuery(this).val();
  var ch = {};
  ch[id] = {}; // <-- here
  ch[id][name] = value;
  alert(ch[id][name]);
});
jQuery('.abc').change(函数(){
var id=jQuery(this.attr('id');
var name=jQuery(this.attr('name');
var value=jQuery(this.val();
var ch={};

ch[id]={};//你能发布你收到的确切错误消息吗?还有,在哪里定义了
ch
呢?在哪里以及如何定义
ch
呢?编辑:省略了数组声明,我的坏!
jQuery('.abc').change(function () {
  var id = jQuery(this).attr('id');
  var name = jQuery(this).attr('name');
  var value = jQuery(this).val();
  var ch = {};
  ch[id] = {}; // <-- here
  ch[id][name] = value;
  alert(ch[id][name]);
});