Javascript 如何在jquery中通过自定义属性获取输入字段的值

Javascript 如何在jquery中通过自定义属性获取输入字段的值,javascript,jquery,Javascript,Jquery,我完全是jquery的初学者 我试过这个 在void元素中,使用将是不合适的。改用input[type=text]是一个空元素,这意味着其中不能有任何子节点,包括text节点 $('input[person]').each(function(index) { alert(index + ': ' + $(this).val()); }); 在void元素中,使用将是不合适的。改用input[type=text]是一个空元素,这意味着其中不能有任何子节点,包括text节点 $('inpu

我完全是jquery的初学者

我试过这个

在void元素中,使用将是不合适的。改用
input[type=text]
是一个空元素,这意味着其中不能有任何子节点,包括
text节点

$('input[person]').each(function(index) {
    alert(index + ': ' + $(this).val());
});
在void元素中,使用将是不合适的。改用
input[type=text]
是一个空元素,这意味着其中不能有任何子节点,包括
text节点

$('input[person]').each(function(index) {
    alert(index + ': ' + $(this).val());
});

正如jQuery文档中所说的

.text()方法不能用于表单输入或脚本

改为使用.val()


正如jQuery文档中所说

.text()方法不能用于表单输入或脚本

改为使用.val()

输入具有读取值的.val()

$('input[person]').each(function(index) {
    alert(index + ': ' + $(this).val());//will read input value
  }
);
输入具有读取值的.val()

$('input[person]').each(function(index) {
    alert(index + ': ' + $(this).val());//will read input value
  }
);

我对你的怀疑有个答案

您必须更改已使用的脚本,如下所示

$('input[person]').each(function(index) {
    alert(index + ': ' + $(this).val());
  }
);

请告诉我您是否发现我的代码对您有用。

对于您的疑问,我有一个答案

   Hey you can use like this:-
   input "type=text" tags have the values not text.
   that's why you have to use .val() instead of .text().

   $('input[person]').each(function(index) {
       alert(index + ': ' + $(this).val());
   });
您必须更改已使用的脚本,如下所示

$('input[person]').each(function(index) {
    alert(index + ': ' + $(this).val());
  }
);

请告诉我您是否发现我的代码对您有用。

使用html5属性代替创建您自己的自定义标记。使用html5属性代替创建您自己的自定义标记。在您的答案中包含一个工作示例总是好的。我已经把它包括进去了。在你的答案中加入一个有效的例子总是好的。我已经包括在内了。
   Hey you can use like this:-
   input "type=text" tags have the values not text.
   that's why you have to use .val() instead of .text().

   $('input[person]').each(function(index) {
       alert(index + ': ' + $(this).val());
   });