【发布时间】:2011-02-04 02:54:35
【问题描述】:
我对 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
});
});
任何帮助或提示将不胜感激。我什至不知道这是否是我应该获取行和列索引的方式。
【问题讨论】:
标签: jquery html css html-table jquery-selectors