HTML表格,点击的行号 [英] HTML table, clicked row's number

查看:466
本文介绍了HTML表格,点击的行号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以找出最近在HTML表格中单击的行号吗? 我需要这种行为来确定是否在当前所选行的顶部和底部单击了use.

Is there any way to find out row number where I recently clicked, in HTML table? I need this behavior to find out whether use clicked on top and bottom of the currently selected row.

我想算法是:

  1. 选择一行
  2. 在同一表格中选择另一行
  3. 确定在(2)处选择的行是否具有比在(1)处选择的行更高或更低的索引

推荐答案

使用jQuery标记问题后,我将为您提供jQuery答案.您可以使用jQuery的 index 方法获取点击行的索引:

As you've tagged the question with jQuery, I'll give you a jQuery answer. You can get the index of the clicked row using jQuery's index method:

$("tr").click(function() {
   console.log($(this).index()); 
});

在click事件处理程序中,您将能够再次使用index方法来获取当前所选行的索引并进行比较,或者执行您想做的任何事情.

Inside the click event handler, you would be able to use the index method again to get the index of the currently selected row and compare them or do whatever you're trying to do.

这篇关于HTML表格,点击的行号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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