获取对角线td jquery的计数 [英] get count of diagonal td jquery
本文介绍了获取对角线td jquery的计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何使用jquery选择器选择所有对角线单元格(td),假设我有一个nxn表,并且我想分别选择``/''和``\''对角线单元格.
像这样的东西
函数getLDCount()
{
返回$(#mytable td")....... length
}
函数getRDCount()
{
返回$(#mytable td").......... length
}
how can i select all diagonal cells(td) using jquery selector , suppose i have a nxn table and i want to select both ''/'' and ''\'' diagonals cells separately.
some thing like this
function getLDCount()
{
return $("#mytable td").......length
}
function getRDCount()
{
return $("#mytable td")..........length
}
推荐答案
(#mytable td")....... length
}
函数getRDCount()
{
return
("#mytable td").......length
}
function getRDCount()
{
return
(#mytable td")..... length
}
("#mytable td")..........length
}
由于表为N x N-长度显然为N.要获得对角线单元,以下逻辑将起作用:
从左到右:
您只需要索引等于行索引的单元格
从右到左:
这比从左到右有点累.以下等式将为您提供所需的单元格:= N-1-Row< index>
这是相同的jsfiddle!
http://jsfiddle.net/kFP4D/ [ ^ ]
希望这会有所帮助!
As the table is N x N - the length is obviously going to be N. To get the diagonal cells, the following logic would work:
Left to right:
You just need the cell whose index is equal to the row index
Right to left:
This is a bit involved than left to right. The following equation would get you the required cells:= N - 1 - Row<index>
Here is a jsfiddle for the same!
http://jsfiddle.net/kFP4D/[^]
Hope this helps!
这篇关于获取对角线td jquery的计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文