Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/80.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 查找特定tr旁边的控件_Javascript_Jquery_Asp.net Mvc 3 - Fatal编程技术网

Javascript 查找特定tr旁边的控件

Javascript 查找特定tr旁边的控件,javascript,jquery,asp.net-mvc-3,Javascript,Jquery,Asp.net Mvc 3,我有一个表,在表中有10行,我想根据id找到一个特定的行,还想找到它旁边的其他行 范例 <table> <tr>1</tr> <tr>2</tr> <tr>3</tr> <tr id="CurrentId">4</tr> <tr> <td>5</td>

我有一个表,在表中有10行,我想根据id找到一个特定的行,还想找到它旁边的其他行

范例

    <table>
       <tr>1</tr>
       <tr>2</tr>
       <tr>3</tr>
       <tr id="CurrentId">4</tr>
       <tr>
          <td>5</td>
       </tr>
       <tr>
          <td>6</td>
       </tr>
       <tr>
          <td>7</td>
       </tr>
       <tr>
          <td>8</td>
       </tr>
       <tr>
          <td>9</td>
       </tr>
       <tr>
          <td>10</td>
       </tr>
   </table>

1.
2.
3.
4.
5.
6.
7.
8.
9
10

在上面的示例中,我希望根据id“CurrentId”查找值4,然后我希望遍历id旁边的所有tr并获取值。在上面的例子中,我只提到了10个,但我不知道会实时生成多少tr。所以我想得到id旁边的所有值。请任何人在同一方面帮助我

使用id选择器选择行和下一行以获取下一行,下一行以获取下一行/行。您还必须在第一行中添加tds,因为您不能将文本直接放入tr

currentRow = $('#CurrentId')
nextRow = $('#CurrentId').next()
nextAllRows = $('#CurrentId').nextAll()

对于这个例子,这里有一种方法

var vals = [];

$('#CurrentId').nextAll().each(function(){
    vals.push($(this).children().html());
});

console.log(vals.join(","));

//output
//5,6,7,8,9,10
这里有一个例子来演示

通过为孩子指定选择器,我更新了小提琴,只获得第一个td:

vals.push($(this).children("td:first-child").html());
你可能不需要它;我把它留给你