使用jQuery获取特定行的匹配td值的下一行td值 [英] Get next row td value of matched td value of a particular row using jquery
问题描述
我是这样的人.
<tr><td>1</td><td>6676</td></tr>
<tr><td>2</td><td>6582</td></tr>
<tr><td>33</td><td>6676</td></tr>
<tr><td>5</td><td>6614</td></tr>
<tr><td>95</td><td>6676</td></tr>
<tr><td>6</td><td>6619</td></tr>
当我单击某行(例如第三行)时,将弹出带有详细信息的窗口.在弹出窗口中,我可以像在gmail中一样导航到上一个记录和下一个记录.
When I click on some row, say 3rd row, I'll get a pop up with the details. In the pop up itself, I can navigate to previous record and next record as we have in gmail.
我将使用find("td:eq(1)").text()
获得第二个td,
I'll get the second td using find("td:eq(1)").text()
,
现在说我在模式窗口中处于第二条记录详细信息中,当我通过捕获td值并将其匹配来执行此操作时,它将不起作用.我不应该为此使用任何计数器.我只是将表的所有记录保留在数组中并进行提取. 这里说currentMysqlId = 6676我单击第三行.我需要按行排列
Now say I'm in 2nd record details in the modal window, and when I do it by catching the td value and matching it, it doesn't work. I should not use any counter for this. I'm just keeping all the records of the table in an array and fetching. Here say currentMysqlId = 6676 I get on clicking on 3rd row. I need to get it row wise
var totalCount = parseInt(totalMsgs); //总行数.
var totalCount = parseInt(totalMsgs); // Total Number of Rows.
for(var i = parseInt(divcurrentCount)+1; i <= parseInt(divcurrentCount)+10; i++){
$('#tblInbox tbody tr:nth-child('+i+')').addClass('active'); // Add class to new page rows.
}
//displayActiveRows(); // Display active rows.
var nextCount = (parseInt($("#currentRecord").val())+1);
if(nextCount == parseInt(totalCount)) {
$('#next').hide();
}
$('#prev').show();
// Fetch next mysqlContent ID because with that ID, the next record details will be fetched.
var currentMysqlId = $("#currentMysqlId").val();
//var nextMySqlId = $('#tblInbox tbody tr td:contains('+currentMysqlId+')').parent("tr").next("tr").find("td:eq(6)").text();
var nextMySqlId = $('#tblInbox tbody tr td:contains('+currentMysqlId+')').parent().next().find("td:eq(6)").text();
alert("next id::"+nextMySqlId);
$('#divcurrentCount').html(nextCount);
renderPopUpData(arrMsgs[nextMySqlId],0); // Display the appropriate data.
我得到的答案很愚蠢,因为如果我在表中搜索6676,它将有很多行.任何帮助将不胜感激.
I'm getting stupid answers because if I search for 6676 in the table, it has many rows. Any help would be greatly appreciated.
推荐答案
您需要td:eq(1)
而不是td:eq(6)
.同样要获得点击的dom引用,您还需要使用$(this)
:
You need td:eq(1)
not td:eq(6)
. also to get the clicked dom refernce you need to use $(this)
:
$(this).parent().next().find("td:eq(1)").text();
这篇关于使用jQuery获取特定行的匹配td值的下一行td值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!