利用JS来控制键盘的上下左右键(示例代码)
来源:互联网 发布:复杂网络节点重要性 编辑:程序博客网 时间:2024/05/18 03:58
这篇文章主要介绍了利用JS来控制键盘的上下左右键示例代码。需要的朋友可以过来参考下,希望对大家有所帮助
这是一个JS初级代码,想学JS的朋友,可以研究下或者扩展下,最好能用JS实现整个键盘的控制,那感觉就很有意思了。
具体代码如下:
代码如下:
<style>
tr.highlight{background:#08246B;color:white;}
</style>
<table border="1" width="70%" id="ice">
<tr>
<td><input type='text'></td>
<td><input type='text'></td>
<td><input type='text'></td>
<td><input type='text'></td>
</tr>
<tr>
<td><input type='text'></td>
<td><input type='text'></td>
<td><input type='text'></td>
<td><input type='text'></td>
</tr>
<tr>
<td><input type='text'></td>
<td><input type='text'></td>
<td><input type='text'></td>
<td><input type='text'></td>
</tr>
<tr>
<td><input type='text'></td>
<td><input type='text'></td>
<td><input type='text'></td>
<td><input type='text'></td>
</tr>
<tr>
<td><input type='text'></td>
<td><input type='text'></td>
<td><input type='text'></td>
<td><input type='text'></td>
</tr>
<!--
//定义初始化行列
var currentLine=-1;
var currentCol=-1;
document.onkeydown=function(e){
e=window.event||e;
switch(e.keyCode){
case 37: //左键
currentCol--;
changeItem();
break;
case 38: //向上键
currentLine--;
changeItem();
break;
case 39: //右键
currentCol++;
changeItem();
break;
case 40: //向下键
currentLine++;
changeItem();
break;
default:
break;
}
}
//方向键调用
function changeItem(){
if(document.all)
var it=document.getElementByIdx_x("ice").children[0];
else
var it=document.getElementByIdx_x("ice");
for(i=0;i<it.rows.length;i++){
it.rows[i].className="";
}
if(currentLine<0){
currentLine=it.rows.length-1;
}
if(currentLine==it.rows.length){
currentLine=0;
}
var objtab=document.all.ice;
var objrow=objtab.rows[currentLine].getElementsByTagName_r("INPUT");
if(currentCol<0){
currentCol=objrow.length-1;
}else if(currentCol==objrow.length){
currentCol=0;
}
objrow[currentCol].select();
//调试使用
it.rows[currentLine].className="highlight";
}
//-->
</script>
这是一个JS初级代码,想学JS的朋友,可以研究下或者扩展下,最好能用JS实现整个键盘的控制,那感觉就很有意思了。
具体代码如下:
代码如下:
<style>
tr.highlight{background:#08246B;color:white;}
</style>
<table border="1" width="70%" id="ice">
<tr>
<td><input type='text'></td>
<td><input type='text'></td>
<td><input type='text'></td>
<td><input type='text'></td>
</tr>
<tr>
<td><input type='text'></td>
<td><input type='text'></td>
<td><input type='text'></td>
<td><input type='text'></td>
</tr>
<tr>
<td><input type='text'></td>
<td><input type='text'></td>
<td><input type='text'></td>
<td><input type='text'></td>
</tr>
<tr>
<td><input type='text'></td>
<td><input type='text'></td>
<td><input type='text'></td>
<td><input type='text'></td>
</tr>
<tr>
<td><input type='text'></td>
<td><input type='text'></td>
<td><input type='text'></td>
<td><input type='text'></td>
</tr>
</table>
unity3d脚本http://www.unitymanual.com/
<!--
//定义初始化行列
var currentLine=-1;
var currentCol=-1;
document.onkeydown=function(e){
e=window.event||e;
switch(e.keyCode){
case 37: //左键
currentCol--;
changeItem();
break;
case 38: //向上键
currentLine--;
changeItem();
break;
case 39: //右键
currentCol++;
changeItem();
break;
case 40: //向下键
currentLine++;
changeItem();
break;
default:
break;
}
}
//方向键调用
function changeItem(){
if(document.all)
var it=document.getElementByIdx_x("ice").children[0];
else
var it=document.getElementByIdx_x("ice");
for(i=0;i<it.rows.length;i++){
it.rows[i].className="";
}
if(currentLine<0){
currentLine=it.rows.length-1;
}
if(currentLine==it.rows.length){
currentLine=0;
}
var objtab=document.all.ice;
var objrow=objtab.rows[currentLine].getElementsByTagName_r("INPUT");
if(currentCol<0){
currentCol=objrow.length-1;
}else if(currentCol==objrow.length){
currentCol=0;
}
objrow[currentCol].select();
//调试使用
it.rows[currentLine].className="highlight";
}
//-->
</script>
0 0
- 利用JS来控制键盘的上下左右键(示例代码)
- JS控制文本框内键盘上下左右键的焦点
- js 上下左右键控制焦点
- 响应键盘的上下左右键
- ASP.NET中键盘上下左右键控制DataGrid的项选择和分页
- js键盘上下左右键如何触发function
- js键盘上下左右键怎么触发function(实例讲解)
- java事件机制之通过上下左右键来控制小球为位置的移动演示
- 上下左右键控制ultraGrid单元格数据的移动
- HTML5-事件-键盘-上下左右键
- HTC G11自带键盘具有上下左右键,导致不希望的逻辑出现
- linux 读取键盘上下左右键小程序
- EXCEL上下左右键
- 上下左右键控制光标在文本框内移动
- android tv盒子播放器控制 监听上下左右键。
- jQuery-利用上下左右键移动输入焦点
- 网页屏蔽(左右键,代码等)的非JS方法
- 网页屏蔽(左右键,代码等)的非JS方法
- u-boot Makefile -- make xxx_config
- [转]Clojure 编程语言
- jQuery 选择器
- 自定义Flex4+的Spark组件part1:使用ActionScript3开发Spark组件Component类
- 【代码积累】JAVA读某文件夹下所有txt类型文件
- 利用JS来控制键盘的上下左右键(示例代码)
- 黑马程序员 正则表达式。
- Div Popup Example
- 【Java TCP/IP Socket】 — close()/shutdownOutput()/shutdownInput() 分析
- unicode字符集与多字节字符集的转换
- js键盘上下左右键怎么触发function(实例讲解)
- Hessian matrix
- Shell 快捷键
- java 从零开始,学习笔记之基础入门<Oracle_查询>(三十四)