使用jQuery通过索引获取td [英] Getting td by index with jQuery

查看:524
本文介绍了使用jQuery通过索引获取td的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如何用jQuery获得单元格的行和列索引,但我无法弄清楚相反的情况。给定一个行列索引,我将如何在此位置访问td?

使用普通的JavaScript:

使用普通的JavaScript:


$ b $

  //表是对您的表的引用
table.rows [rowIndex] .cells [columnIndex]

参考: HTMLTableElement HTMLTableRowElement




jQuery,你可以使用 .eq()

  $('#table tr')。eq(rowIndex).find('td')。eq(columnIndex) 
//或
$('#table tr:eq('+ rowIndex +')td:eq('+ columnIndex +')')


I know how to get a cell's row and column index with jQuery, but I can't figure out the reverse. Given a row and column index, how would I access the td at this location?

解决方案

With plain JavaScript:

// table is a reference to your table
table.rows[rowIndex].cells[columnIndex]

Reference: HTMLTableElement, HTMLTableRowElement


With jQuery, you could use .eq():

$('#table tr').eq(rowIndex).find('td').eq(columnIndex)
// or
$('#table tr:eq(' + rowIndex + ') td:eq(' + columnIndex + ')')

这篇关于使用jQuery通过索引获取td的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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