我想将鼠标拖到单元格上,然后选择单元格下的任何内容。只有它下面的单元格被选中。如果用户以之字形方式移动鼠标,则不会发生选择。我怎样才能做到这一点。
$(".csstablelisttd").live('mousedown', function (e){
//This line gets the index of the first clicked row.
lastRow = $(this).closest("tr")[0].rowIndex;
rowIndex = $(this).closest("tr").index();
colIndex = $(e.target).closest('td').index();
$(".csstdhighlight").removeClass("csstdhighlight");
$('#tableAppointment tr').eq(rowIndex).find('td').eq(colIndex).addClass('csstdhighlight');
flag = true;
return false;
});
document.onmousemove = function () { return false; };
$(".csstablelisttd").live('mouseenter', function (e){
// Compares with the last and next row index.
currentRow = $(this).closest("tr")[0].rowIndex;
currentColoumn = $(e.target).closest('td').index();
if (lastRow == currentRow || lastRow == currentRow - 1 || lastRow == currentRow + 1){
lastRow = $(this).closest("tr")[0].rowIndex;
}else{
return;
}
if (flag){
$('#tableAppointment tr').eq(currentRow ).find('td').eq(currentColoumn ).addClass('csstdhighlight');
e.preventDefault();
flag = false;
}
});