小编Mar*_*ark的帖子

如果我知道单元格的行和列索引,如何更改HTML表格单元格中的属性?

我对jQuery一无所知,但我是一位经验丰富的C++程序员(不确定是否有帮助或伤害).我找到了jQuery代码,当用户点击该单元格时,它会为我提供HTML表格中单元格的行和列索引.使用这样的行列索引号,我需要在先前选择的单元格和单击的单元格中更改属性的值.使用以下代码生成并保存索引号:

var $trCurrent = 0; // Index of cell selected when page opens 
var $tdCurrent = 0; // i.e., previously selected cell

$(document).ready(function ()
{
    $("td").click(function ()
    {
        // How toclear previously selected cell's attribute here? ('class', 'recent')
        var oTr = $(this).parents("tr");
        $tdCurrent = oTr.children("td").index(this);

     });
    $("tr").click(function ()
    {
        $trCurrent = $(this)[0].rowIndex;
        // How to set new attributes here? ('class', 'current');
        // and continue work using information from currently selected cell

     });
});
Run Code Online (Sandbox Code Playgroud)

任何帮助或提示将不胜感激.我甚至不知道这是否应该得到行和列的索引.

html css jquery html-table jquery-selectors

1
推荐指数
1
解决办法
1242
查看次数

标签 统计

css ×1

html ×1

html-table ×1

jquery ×1

jquery-selectors ×1