[英]JQuery prev() with selector
The goal is to dynamically prepopulate a modal form with data that exists in a table. 目标是使用表中存在的数据动态地预先填充模式形式。 Here is my existing code:
这是我现有的代码:
<table>
<tr>
<th>header1</th>
<th>header2</th>
...
</tr>
<tr>
<th class='column1'>A</th>
<th class='column2'>B</th>
...
</tr>
</table>
Jquery: jQuery:
$(document).ready(function() {
$('.open_dialog').click(function(){
$('#opName').val($(this).prev().prev().prev().text());
$('#opPrefix').val($(this).prev().prev().text());
$('#opDefaultErrorString').val($(this).prev().text());
$('#formModal').modal('show');
return false;
});
...
so I have had to ridiculously call prev() over and over because for some reason when i try to directly go to the column I want by using prev('.column1').text() it gives "an empty string". 所以我不得不一遍又一遍地荒谬地调用prev(),因为出于某种原因,当我尝试通过使用prev('。column1')。text()直接转到我想要的列时,它给出了“空字符串”。
What am I missing here? 我在这里想念什么?
.prev()
can only return the immediately preceding element. .prev()
只能返回前一个元素。
You want .prevAll('.column1')
. 您需要
.prevAll('.column1')
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.