确定单击了哪个单元格以及列的标题 [英] Determening which cell is clicked and the header of the column

查看:91
本文介绍了确定单击了哪个单元格以及列的标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个名为tb的表有n行和m列,

表示每行有mtd标记。



当我点击一个td whick id调用''stdid''时,如何得到它''row'的第一个''td''和列'标题?

A table called "tb" has n rows and m columns,
means each row has m "td" mark.

How can I get it''s row''s first ''td'' and column''s header when I click one td whick id call ''stdid''?

推荐答案

当你提到HTML元素,而不是ASP.NET控件(比如 GridView )时,你应该只得到JavaScript的答案。



在这种情况下,我不确定你是否需要知道特定的< td> 元素,因为你可以添加一个处理每个< td> 元素上的 onclick 事件,这样:

http://www.w3schools.com/jsref/event_onclick.asp [ ^ ]。



相同关于< th> 或任何其他元素的事情。



-SA
As you mention HTML elements, not ASP.NET controls (like GridView), you should get an answer of JavaScript only.

In this case, I''m not sure you ever need to know the particular <td> element, as you can add a handler to the onclick event on each <td> element individually, this way:
http://www.w3schools.com/jsref/event_onclick.asp[^].

Same thing about <th> or any other element.

—SA


与谢尔盖假设我们正在谈论前端代码一样,我会继续说路径并给出一个JQuery解决方案,因为它听起来像你的路障是如何遍历DOM以找到相应的第一列TD。



获取第一列的内容包含TD的行的TD点击,你可以使用

Going with Sergey''s assumption that we''re talking about front-end code, I will continue down that path and give a JQuery solution, as it sounds like your roadblock is how to traverse the DOM to find the corresponding first column TD.

To get the contents of the first TD of the row containing the TD clicked, you could use
var firstItem =


this )。nearest(' tr')。children(' :first-child')。html() ;
(this).closest('tr').children(':first-child').html();



如果第一个TD本身不可点击,代码可以简化:


The code could be simplified if the first TD isn''t itself clickable:

var firstItem =


这篇关于确定单击了哪个单元格以及列的标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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