简体   繁体   English

单击链接时使用 javascript 获取表行的内容

[英]Fetch the contents of a table row using javascript when a link is clicked

I have a dynamic table and in one of the attributes of that table I have edit link, I want to fetch the data adjacent to that link if that link is clicked.我有一个动态表,并且在该表的一个属性中我有编辑链接,如果单击该链接,我想获取与该链接相邻的数据。

在此处输入图像描述

For example if I click Edit on line number 2, I should be able to retrieve Demo User, demouser, demo@demo.com and User using javascript.例如,如果我在第 2 行单击 Edit,我应该能够检索 Demo User、demouser、demo@demo.com 和 User using javascript。

The key is to access the row and then find elements inside that row:关键是访问该,然后在该行内查找元素:

$('.your-link').click(function () {
    const row = $(this).closest('tr');
    const whatever = row.find('.whatever').text();
})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM