jQuery遍历表列 [英] jQuery iterate through table column

查看:70
本文介绍了jQuery遍历表列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想遍历表格列.给定我有一个单元格ID,然后我想要获取该列中其余单元格的值.

I'd like to iterate through a tables columns. Given I have a cell Id, I then want to get the values of the rest of the cells in that column.

这样做的原因是,我想添加一些验证,以便一列中的3个单元格不能全部包含相同的类.

The reason for this is, I want to add some validation so that 3 cells in a column, can't all contain the same class.

我愿意使用jQuery或PHP.

I'm open to ideas using both jQuery or PHP.

如果您需要更多信息,请发表评论.

If you require more information, please comment.

推荐答案

在JQuery中获取项目的列:

In JQuery to get an item's column:

var column = $('#myID').index();

要通过第n列来解析表格:

To parse through the table by the nth column:

var columnNth = $('#myID').index() + 1;
var items = [];


$('#tblID tbody tr td:nth-child('+columnNth +')').each( function(){
   //add item to array
   items.push( $(this).attr('class'); );       
});

这篇关于jQuery遍历表列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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