表每行第一列的JQuery选择器

表每行第一列的JQuery选择器,jquery,jquery-selectors,Jquery,Jquery Selectors,我想选择每一行的第一列。但是第一列可能有“rowspan”属性 就这样 html: 第一 前2名 前三名 第二 第二个3 第三个1 第三个2 第三 我选择了第一列,但得到了这些结果 $("tr td:first-child"); "<td rowspan="2">first1<td>,<td>second2<td>,<td>third1<td>" $(“tr td:第一个孩子”); “第一个1,第二个2,第三个1”

我想选择每一行的第一列。但是第一列可能有“rowspan”属性

就这样

html:


第一
前2名
前三名
第二
第二个3
第三个1
第三个2
第三
我选择了第一列,但得到了这些结果

$("tr td:first-child");

"<td rowspan="2">first1<td>,<td>second2<td>,<td>third1<td>"
$(“tr td:第一个孩子”);
“第一个1,第二个2,第三个1”
预期结果是

"<td rowspan="2">first1<td>,<td>third1<td>"
“第一个1,第三个1”
我想将这些列设置为表左右滚动的固定列


谢谢。

尽管有许多插件可供您使用,但类似的内容可能会让您开始使用

var $rows = $('tr'), skipCount = 0;

var $cloneTable = $('<table>');
$rows.each(function () {
    var $row = $(this), $firstCell;
    var $newRow = $('<tr>');
    if (!skipCount) {
        $firstCell = $row.find('td').first();
        $newCell =$firstCell.clone().height($firstCell.height());        
        $newRow.append($newCell);
        var rowSpan = +$firstCell.attr('rowspan');
        if (rowSpan) {
            skipCount = rowSpan-1;
        }
    } else {
        skipCount--;
    }
    $cloneTable.append($newRow);

});
var$rows=$('tr'),skipCount=0;
变量$cloneTable=$('');
$rows.each(函数(){
var$row=$(此),$firstCell;
变量$newRow=$('');
如果(!skipCount){
$firstCell=$row.find('td').first();
$newCell=$firstCell.clone().height($firstCell.height());
$newRow.append($newCell);
var rowSpan=+$firstCell.attr('rowSpan');
如果(行跨度){
skipCount=行span-1;
}
}否则{
skipCount--;
}
$cloneTable.append($newRow);
});

预期结果是什么<代码>“第一个1,第三个1”?您想用它们做什么?创建一个数据数组和添加一个类之间会有很大的区别这些结果有什么问题
second2
是第二行的第一列。我已更改了问题说明。谢谢。起初我想使用选择器完成它。现在这是实现它的唯一方法。谢谢。
var $rows = $('tr'), skipCount = 0;

var $cloneTable = $('<table>');
$rows.each(function () {
    var $row = $(this), $firstCell;
    var $newRow = $('<tr>');
    if (!skipCount) {
        $firstCell = $row.find('td').first();
        $newCell =$firstCell.clone().height($firstCell.height());        
        $newRow.append($newCell);
        var rowSpan = +$firstCell.attr('rowspan');
        if (rowSpan) {
            skipCount = rowSpan-1;
        }
    } else {
        skipCount--;
    }
    $cloneTable.append($newRow);

});