我需要在特定行的table
内的input
中查找信息。
我有这个
var myElements = $('#myTable tbody').find('tr');
console.log(myElements);
这会正确显示表格中的项目
[tr.rowcenter, tr.rowcenter, prevObject: e.fn.e.init[1], context: document, selector: "#myTable tbody tr", constructor: function, init: function…]
0: tr.rowcenter <- OK
1: tr.rowcenter <- OK
context: document
length: 2
prevObject: e.fn.e.init[1]
selector: "#tRangos tbody tr"
__proto__: e[0]
在本例中只有 2 行
但是当我想连续查看时,就像这样
myElements[i].find(".r_min").val(); //inside have .r_min , .r_max and .r_val
我明白了
Uncaught TypeError: myElements[i].find is not a function
当 console.log(myElements[i])
只看到 HTML 元素时
<tr class="rowcenter">
<td>
<input class="r_min" value="10.0">
</td>
<td>
<input class="r_max" value="12.0">
</td>
<td>
<input class="r_val" value="50.00">
</td>
<td> other trash</td>
</tr>
为什么?
注意我使用 jQuery 1.7.2
最佳答案
使用myElements.eq(i)
而不是myElements[i]
。这将过滤掉除第 i 行之外的所有行。
关于javascript - 使用 find 在容器内进行 jQuery 搜索失去了对 jQuery 的控制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30142655/