Home  >  Article  >  Web Front-end  >  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
WBOYOriginal
2016-05-16 18:38:111264browse
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>
Statement:
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