Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/461.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用jQuery获取表内的文本框值_Javascript_Jquery - Fatal编程技术网

Javascript 使用jQuery获取表内的文本框值

Javascript 使用jQuery获取表内的文本框值,javascript,jquery,Javascript,Jquery,Html表格 <table id="tb"> <tr> <th>First Name</th> <th>Last Name </th> <th>Coutry</th> </tr> <tr> <td><input type="text" id="FName"/> </td> <td><input type

Html表格

<table id="tb">
<tr>
  <th>First Name</th>
  <th>Last Name </th>
  <th>Coutry</th>
</tr>

<tr>
  <td><input type="text" id="FName"/> </td>
  <td><input type="text" id="LName"/> </td>
   <td><input type="text" id="Country"/> </td>
</tr>

<tr>
  <td><input type="text" id="FName"/> </td>
  <td><input type="text" id="LName"/> </td>
   <td><input type="text" id="Country"/> </td>
</tr>
</table>
但是我得到了未定义的值

我想从表中的文本框中获取所有值


请帮助我解决此问题。

该行使用选择器切换了上下文

$(row, "input").each(function (i, sr) {
应该是

$("input", row).each(function (i, sr) {


该行使用选择器切换了上下文

$(row, "input").each(function (i, sr) {
应该是

$("input", row).each(function (i, sr) {

你可以用

$('#tb tr').each(function(i, row) {
   $(this).find('input').each(function() {
     alert($(this).val())
   })
});
工作演示

$('#tb tr')。每个(函数(i,行){
$(this).find('input').each(function(){
警报($(this.val())
})
});

名字
姓
库特里
您可以使用

$('#tb tr').each(function(i, row) {
   $(this).find('input').each(function() {
     alert($(this).val())
   })
});
工作演示

$('#tb tr')。每个(函数(i,行){
$(this).find('input').each(function(){
警报($(this.val())
})
});

名字
姓
库特里
您只需使用:

$('#tb tr input[type=text]').each(function(){

  alert($(this).val());

});
您只需使用:

$('#tb tr input[type=text]').each(function(){

  alert($(this).val());

});

ID必须是唯一的。另外,何时/如何执行jQuery?在按钮单击事件中。我无法控制ID,因为它们是动态生成的。ID必须是唯一的。另外,何时/如何执行jQuery?在按钮单击事件中。我无法控制ID,因为它们是动态生成的