从特定的tr获取td值(使用鼠标悬停) [英] Get td value from specific tr (with mouse hover)
问题描述
我的问题是js可排序表,我也为此使用了鼠标悬停.问题是,当我重新使用表时,悬停网址没有更新,我在寻找如何获取特定tr的方法,因此选择了第一个td的值.
My problem is js sortable table that I also using mouse hover for it. The problem is when I resort my table the hover url is not updating and I looking for how I can get for specific tr I selected the value of first td.
我尝试了不同的变化,例如:
I tried with different variations such as:
$this.find('td:eq(0)')
或使用
getElementById("trselect")
什么都行不通.
我将它与鼠标悬停一起使用,并且可能正在寻找类似的东西:
I use it with both mouse hover and probably looking for something like:
document.location.href = "details/" + $('tr').find('td:first-child').text();
推荐答案
纯JavaScript解决方案
有一堆jQuery答案,但没有jQuery标签,因此我为您提供了一个纯JavaScript解决方案.为这个简单的任务安装大型库似乎毫无意义.
Pure JavaScript Solution
There are a bunch of jQuery answers but no jQuery tag so I'm offering a pure JavaScript solution for you. Installing a large library for this simple task seems pointless.
您可以像这样将行分配给Javascript变量,然后查找鼠标悬停.
You can assign the row to a Javascript variable like this, and look for mouseover.
要获取第一个TD的内容,可以使用以下函数:
To get the first TD's content, you can use a function like this:
function getFirstTdContent(row) {
elem = row.children[0];
alert(elem.textContent); // Do whatever you want to do with the content here
}
要调用它,请像这样声明您的行:
To call it, declare your row like this:
<tr onmouseover='getFirstTdContent(this);'>
<td>This should be returned</td>
<td>This should not be returned</td>
</tr>
这篇关于从特定的tr获取td值(使用鼠标悬停)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!