我需要以下問題的專家的幫助,因爲它超越了我在JavaScript中編程的知識水平。添加使用向上和向下箭頭鍵選擇表格行的功能
考慮到現有的JavaScript編碼,我該如何捎帶並添加到現有編碼中,以便爲用戶添加功能,以便用戶使用向上和向下箭頭鍵在表格中滾動時滾動瀏覽表格順便說一句,標題列豁免)它會突出顯示選定的行並更改其行顏色。
需要注意的一點是,如果現有的表格行被選中,並且我點擊了向上或向下箭頭鍵,它將移動到並突出顯示上一行和下一行。這裏的一些邏輯是,我猜測人們需要找到行索引來做到這一點。就像我說的那樣,這遠遠超出我所知道的如何去做。
非常感謝和對您的幫助非常感謝。
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
tr.normal td {
color: black;
background-color: white;
}
tr.highlighted td {
color: white;
background-color: red;
}
</style>
</head>
<body>
<div id="results" class="scrollingdatagrid">
<table id="mstrTable" cellspacing="0" border="1">
<thead>
<tr>
<th>File Number</th>
<th>Date1</th>
<th>Date2</th>
<th>Status</th>
<th>Num.</th>
</tr>
</thead>
<tbody>
<tr>
<td>KABC</td>
<td>09/12/2002</td>
<td>09/12/2002</td>
<td>Submitted</td>
<td>1</td>
</tr>
<tr>
<td>KCBS</td>
<td>09/11/2002</td>
<td>09/11/2002</td>
<td>Lockdown</td>
<td>2</td>
</tr>
<tr>
<td>WFLA</td>
<td>09/11/2002</td>
<td>09/11/2002</td>
<td>Submitted</td>
<td>3</td>
</tr>
<tr>
<td>WTSP</td>
<td>09/15/2002</td>
<td>09/15/2002</td>
<td>In-Progress</td>
<td>4</td>
</tr>
</tbody>
</table>
</div>
<script type="text/javascript">
(
function() {
var trows = document.getElementById("mstrTable").rows;
for (var t = 1; t < trows.length; ++t) {
trow = trows[t];
trow.className = "normal";
trow.onclick = highlightRow;
}//end for
function highlightRow() {
for (var t = 1; t < trows.length; ++t) {
trow = trows[t];
if (trow != this) { trow.className = "normal" }
}//end for
this.className = (this.className == "highlighted")?"normal":"highlighted";
}//end function
}//end function
)();//end script
</script>
</body>
</html>
http://jsfiddle.net/7ecNj/2/ –