Home > Web Front-end > JS Tutorial > js code for selecting table rows using the up and down keys on the keyboard_javascript skills

js code for selecting table rows using the up and down keys on the keyboard_javascript skills

WBOY
Release: 2016-05-16 18:38:11
Original
1285 people have browsed it
js code for selecting table rows using the up and down keys on the keyboard_javascript skills

[Ctrl A select all Note: If you need to introduce external Js, you need to refresh to execute
]<script> var rowNo= -1; var tableId = 'tb'; var inputId = 'show'; var selectedColor = "#FF0000" function document.onkeydown() { //事件的标识代码 if (event.keyCode == 38) { for(var k=0;k<document.getElementById(tableId).rows.length;k++) { document.getElementById(tableId).rows(k).bgColor="#FFFFFF"; } if(rowNo == 0) { rowNo++; } document.getElementById(tableId).rows(--rowNo%document.getElementById(tableId).rows.length).bgColor=selectedColor; document.getElementById(inputId).value=document.getElementById(tableId).rows(rowNo%document.getElementById(tableId).rows.length).innerText; } //事件的标识代码 if (event.keyCode== 40) { for(var k=0;k<document.getElementById(tableId).rows.length;k++) { document.getElementById(tableId).rows(k).bgColor="#FFFFFF"; } document.getElementById(tableId).rows(++rowNo%document.getElementById(tableId).rows.length).bgColor=selectedColor; document.getElementById(inputId).value=document.getElementById(tableId).rows(rowNo%document.getElementById(tableId).rows.length).innerText; } } </script>
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template