如何使用jQuery獲取單擊的表格單元格的行和列號,即$("td").onClick(function(event){ var row = ... var col = ...});
3 回答

30秒到達戰(zhàn)場
TA貢獻1828條經(jīng)驗 獲得超6個贊
$('td').click(function() {
var myCol = $(this).index();
var $tr = $(this).closest('tr');
var myRow = $tr.index();
});

偶然的你
TA貢獻1841條經(jīng)驗 獲得超3個贊
點擊可獲取COLUMN INDEX:
$(this).closest("td").index();
點擊可獲得ROW INDEX:
$(this).closest("tr").index();

慕工程0101907
TA貢獻1887條經(jīng)驗 獲得超5個贊
您可以在給定的上下文中使用Core / index函數(shù),例如,可以檢查TD的父TR中的索引以獲取列號,還可以檢查Table上的TR索引以獲取行號:
$('td').click(function(){
var col = $(this).parent().children().index($(this));
var row = $(this).parent().parent().children().index($(this).parent());
alert('Row: ' + row + ', Column: ' + col);
});
在此處查看運行示例。
- 3 回答
- 0 關(guān)注
- 467 瀏覽
添加回答
舉報
0/150
提交
取消