在JQuery中,如何获取相邻的表格单元格? [英] In JQuery how can I get the adjacent table cell?

查看:97
本文介绍了在JQuery中,如何获取相邻的表格单元格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含多行的表,每行包含三个单元格.每个单元格都包含一个文本框,因此如下所示:

I have a table with multiple rows, and each row contains three cells. Each cell contains a textbox, so it looks like this:

XXXX   XXXX   XXXX

在第一个文本框的keyup事件中,我希望将其内容复制到第二个文本框,而不是第三个文本框.

on the keyup event of the first textbox, I want its contents to be copied into the second textbox, but not the third textbox.

我的keyup事件,我可以获得对第一个文本框的引用.做.parent()会给我单元格,如果我愿意,再次做.parent()会给我行.

my keyup event I can get a reference to the first textbox. Doing .parent() will give me the cell, and if I want, doing .parent() again will give me the row.

我可以使用哪种JQuery来获取相邻的文本框?

What JQuery can I use to get the adjacent textbox?

推荐答案

您可以使用 .next() 获得下一个兄弟姐妹,例如:

You can use .next() to get the next sibling, like this:

var nextTD = $(this).closest("td").next();
//for your case:
$(this).closest("td").next().find("input").val($(this).val());

.parent() 也可以使用, 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆