0

Sorry for the vague title but here is my problem :

I have an HTML table that I am generating from Javascript, this is fine and the table generates as expected with no problems.

When the user clicks on a cell it will highlight that cell (or un-highlight if the cell is highlighted), this again works fine.

We then needed the ability to drag over the cells (whilst the mouse is down) and highlight the cells they hovered, this I managed to do but it was not the best solution so it was asked if we could select a cell, then hover to another cell and all the cells in between become highlighted.

For example :

Start Cell = Row 1, Cell 1

End Cell = Row 3, Cell 3

Highlighted Cells = R1C1, R1C2, R1C3, R2C1, R2C2, R2C3, R3C1, R3C2, R3C3.

I have managed to sort of get this solution to work, here is a JSFiddle to show the solution, if you click on the first cell and hold the mouse down and drag to the last cell it works fine.

My Problem is that if you drag from the last cell (bottom left) to the top cell (top right) the highlighting effect seems to stall randomly until you are on row 2 or 3.

Is there any reason why this would be occurring? Is my code incorrect / inefficient for this?

I've been stuck with this for sometime and can't seem to find any reason why it would be occurring.

Any help is greatly appreciated.

P.S. - This solution MUST be a fully Javascript solution, jQuery cannot be used for this solution unfortunately as we require this to be a single HTML File and must be possible to use without an Internet Connection.

4

1 回答 1

3

当您提取 rowNum 和 cellNum 时,在 ClickCell 函数中,您必须将值转换为整数:

var RowNum = parseInt(cellID.substring(1, cellID.indexOf('C')), 10);
var CellNum = parseInt(cellID.substring(cellID.indexOf('C') + 1, cellID.length), 10);
于 2013-09-30T13:51:06.750 回答