<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD> <BODY onkeydown= "do_change()">
<table id="tab">
<tr><td><input type = "text" ></td><td><input type = "text" ></td></tr>
<tr><td><input type = "text" ></td><td><input type = "text" ></td></tr>
<tr><td><input type = "text" ></td><td><input type = "text" ></td></tr>
<tr><td><input type = "text" ></td><td><input type = "text" ></td></tr>
</table>
</BODY>
</HTML>
<SCRIPT LANGUAGE="JavaScript">
<!--
function do_change(){
//var tab = document.getElementById("tab");
/// tab.rows[0].cells[0].firstChild.focus();
//alert(tab.rows.length)
}
//-->
</SCRIPT>各位大虾可以把上面代码复制下来 看看 本人想实现的效果为当本人按键盘上的方向键时 使光标可以在各个文本框内来回动(和在EXCEL中一样)!
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD> <BODY onkeydown= "do_change()">
<table id="tab">
<tr><td><input type = "text" ></td><td><input type = "text" ></td></tr>
<tr><td><input type = "text" ></td><td><input type = "text" ></td></tr>
<tr><td><input type = "text" ></td><td><input type = "text" ></td></tr>
<tr><td><input type = "text" ></td><td><input type = "text" ></td></tr>
</table>
</BODY>
</HTML>
<SCRIPT LANGUAGE="JavaScript">
<!--
function do_change(){
//var tab = document.getElementById("tab");
/// tab.rows[0].cells[0].firstChild.focus();
//alert(tab.rows.length)
}
//-->
</SCRIPT>各位大虾可以把上面代码复制下来 看看 本人想实现的效果为当本人按键盘上的方向键时 使光标可以在各个文本框内来回动(和在EXCEL中一样)!
解决方案 »
- 一个简单的语法高亮实现
- js原型继承问题,请教了(腾讯的一道面试题)
- 用js验证邮箱是否合法
- 看起来很牛的CSS仿FLASH图片轮换,求前辈指点更改一下命名 拜谢!
- 急!!~~js怎样向select中添加option~~
- (散分)一个循环用法的问题,那一个会更好呢
- 如何知道一个javascript是什么类型的对象,javascript中有无类似于java的obj.getClass()方法?
- 用鼠标拖动改变tabletable边框大小,如何实现
- user_id 问题,高手送高分!!!
- vue项目问题
- 关于模版中使用弹出式菜单的问题
- [关于iframe]如何从住页面控制第二级iframe的href啊?
<div contentEditable="true">
<table border="1">
<tr><td> </td><td> </td></tr>
<tr><td> </td><td> </td></tr>
<tr><td> </td><td> </td></tr>
<tr><td> </td><td> </td></tr>
</table>
</div>
<HEAD>
<TITLE> New Document </TITLE>
<script>
function do_change(){
var cur_focus=hidden1.value;
var row=cur_focus.substring(1,2);
var col=cur_focus.substring(2,3);
if(event.keyCode==40&&row!=4){
eval("t"+(parseInt(row)+1)+col).focus();
hidden1.value="t"+(parseInt(row)+1)+col;
}else if(event.keyCode==38&&row!=1){
eval("t"+(parseInt(row)-1)+col).focus();
hidden1.value="t"+(parseInt(row)-1)+col;
}else if(event.keyCode==37&&col!=1){
eval("t"+row+(parseInt(col)-1)).focus();
hidden1.value="t"+row+(parseInt(col)-1);
}else if(event.keyCode==39&&col!=2){
eval("t"+row+(parseInt(col)+1)).focus();
hidden1.value="t"+row+(parseInt(col)+1);
}
}
function b(){
t11.focus();
hidden1.value="t11";
}
</script>
</HEAD>
<BODY onkeydown="do_change()" onload="b()">
<table id="tab">
<tr><td><input type="text" name="t11" id="t11"></td><td><input type = "text" name="t12" id="t12"></td></tr>
<tr><td><input type="text" name="t21" id="t21"></td><td><input type = "text" name="t22" id="t22"></td></tr>
<tr><td><input type="text" name="t31" id="t31"></td><td><input type = "text" name="t32" id="t32"></td></tr>
<tr><td><input type="text" name="t41" id="t41"></td><td><input type = "text" name="t42" id="t42"></td></tr>
</table>
<input type=hidden id="hidden1" value="">
</BODY>
</HTML>
<HEAD>
<TITLE> New Document </TITLE>
<script>
function do_change(){
var cur_focus=hidden1.value;
var row=cur_focus.substring(1,2);
var col=cur_focus.substring(2,3);
if(event.keyCode==40&&row!=4){
eval("t"+(parseInt(row)+1)+col).focus();
hidden1.value="t"+(parseInt(row)+1)+col;
}else if(event.keyCode==38&&row!=1){
eval("t"+(parseInt(row)-1)+col).focus();
hidden1.value="t"+(parseInt(row)-1)+col;
}else if(event.keyCode==37&&col!=1){
eval("t"+row+(parseInt(col)-1)).focus();
hidden1.value="t"+row+(parseInt(col)-1);
}else if(event.keyCode==39&&col!=2){
eval("t"+row+(parseInt(col)+1)).focus();
hidden1.value="t"+row+(parseInt(col)+1);
}
}
function a(obj){
hidden1.value=obj.id;
}
function b(){
t11.focus();
}
</script>
</HEAD>
<BODY onkeydown="do_change()" onload="b()">
<table id="tab">
<tr>
<td><input type="text" name="t11" id="t11" onfocus="a(this)"></td>
<td><input type="text" name="t12" id="t12" onfocus="a(this)"></td>
</tr>
<tr>
<td><input type="text" name="t21" id="t21" onfocus="a(this)"></td>
<td><input type="text" name="t22" id="t22" onfocus="a(this)"></td>
</tr>
<tr>
<td><input type="text" name="t31" id="t31" onfocus="a(this)"></td>
<td><input type="text" name="t32" id="t32" onfocus="a(this)"></td>
</tr>
<tr>
<td><input type="text" name="t41" id="t41" onfocus="a(this)"></td>
<td><input type="text" name="t42" id="t42" onfocus="a(this)"></td>
</tr>
</table>
<input type=hidden id="hidden1" value="">
</BODY>
</HTML>