获取td元素而不是其内容

时间:2015-08-01 04:43:18

标签: jquery sorting html-table

这段代码取自here

// Fetch the table's data and store it in a dictionary (assoc array).
if (!table.tBodies.length) { return; }// No data in table.
var tablebody = table.tBodies[0];
var cellDictionary = [];

for (var y = 0, row; row = tablebody.rows[y]; y++)
{
    var cell;

    if (row.cells.length)
    {
        cell = row.cells[column];
    }
    else
    { // Dodge Safari 1.0.3 bug
        cell = row.childNodes[column];
    }

    cellDictionary[y] = [TableSort.dom2txt_(cell), row];
}

如注释行所示,它会获取单元格内容然后对其进行排序。我想要它做的是获取元素(就是你所谓的那个?)值,而不是像

<td actual_value="0">1/1/1970</td>

在上面的td中,它将获取值“0”而不是“1/1/1970”进行排序。那是可行的吗?

2 个答案:

答案 0 :(得分:3)

.getAttribute("actual_value");

或者使用jQuery

.attr("actual_value");

答案 1 :(得分:1)

如果您使用的是JQuery,可以使用

.attr('actual_value')
相关问题