使用 Jquery 将 div 与相同计数器链接
我有一个使用 PHP 从数据库获取数据的表。
该表包含父级 2 个元素,假设它们是:
Name Surname << table row id = info1
Name Surname << table row id = info2
在每一行下面,还有默认隐藏的另一行。单击名字时,这就是我希望它显示的方式:
Name Surname << table row id = info1
DOB City << table row id = infoSub1
Name Surname << table row id = info2
<< table row id = infoSub2 NOT DISPLAYED
如何以最有效的方式实现这一点?
谢谢
I have a table which gets data from the database using PHP.
The table contains the parent 2 elements, lets say they are:
Name Surname << table row id = info1
Name Surname << table row id = info2
Beneath every row, there is another row which is hidden by default. When first name is clicked, this is how i want it to display:
Name Surname << table row id = info1
DOB City << table row id = infoSub1
Name Surname << table row id = info2
<< table row id = infoSub2 NOT DISPLAYED
How can I implement this in the most effective way?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
然后对 info2 和 infoSub2 执行相同的操作:)
Then do the same for info2 and infoSub2 :)
如果您可以为父行指定一个类(例如
parent
),那么您可以使用.nextUntil()
:这仅选择所有
元素,不是
.parent
跟随单击的行,直到找到该行。这允许您在中间插入任意数量的非父行,并且可以正确切换它们。如果您有一个包含很多行的长表,请使用.delegate()
以类似的方式:其行为相同,但会将一个事件处理程序附加到
(而不是每个父级
)。
If you can give the parent rows a class (for example
parent
), then you can make this very generic with.nextUntil()
:This just selects all the
<tr>
elements that aren't.parent
following the clicked row until it finds one that is. This allows you any number of non-parent rows in-between, and it would toggle them all correctly. If you have a long table with lots of rows, use.delegate()
in a similar way:This behaves the same, but would attach one event handler to the
<table>
(rather than one per parent<tr>
).