我的朋友写了以下代码:
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>无标题页</title>
<script language="javascript" type="text/javascript">
function document.onkeydown()
{
if(event.keyCode==96)
Text1.focus();
if(event.keyCode==97)
Text2.focus();
if(event.keyCode==98)
Text3.focus();
if(event.keyCode==99)
Text4.focus();
if(event.keyCode==100)
Text5.focus();
if(event.keyCode==101)
Text6.focus();
if(event.keyCode==102)
Text7.focus();
if(event.keyCode==103)
Text8.focus();
if(event.keyCode==104)
Text9.focus();
if(event.keyCode==105)
Text10.focus();
}
</script>
</head>
<body>
<input id="Text1" type="text" />
<input id="Text4" type="text" />
<input id="Text2" type="text" />
<input id="Text3" type="text" onclick="return Text3_onclick()" /><br />
<input id="Text5" type="text" />
<input id="Text6" type="text" />
<input id="Text7" type="text" />
<input id="Text8" type="text" />
<br />
<input id="Text9" type="text" />
<input id="Text10" type="text" /> </body>
</html>
_______
但是当我输入在键盘上输入10的时候,会在对话框1和10中同时显示1和0两个数,有没有办法可以使1和10在键盘上输入的时候区分开来?
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>无标题页</title>
<script language="javascript" type="text/javascript">
function document.onkeydown()
{
if(event.keyCode==96)
Text1.focus();
if(event.keyCode==97)
Text2.focus();
if(event.keyCode==98)
Text3.focus();
if(event.keyCode==99)
Text4.focus();
if(event.keyCode==100)
Text5.focus();
if(event.keyCode==101)
Text6.focus();
if(event.keyCode==102)
Text7.focus();
if(event.keyCode==103)
Text8.focus();
if(event.keyCode==104)
Text9.focus();
if(event.keyCode==105)
Text10.focus();
}
</script>
</head>
<body>
<input id="Text1" type="text" />
<input id="Text4" type="text" />
<input id="Text2" type="text" />
<input id="Text3" type="text" onclick="return Text3_onclick()" /><br />
<input id="Text5" type="text" />
<input id="Text6" type="text" />
<input id="Text7" type="text" />
<input id="Text8" type="text" />
<br />
<input id="Text9" type="text" />
<input id="Text10" type="text" /> </body>
</html>
_______
但是当我输入在键盘上输入10的时候,会在对话框1和10中同时显示1和0两个数,有没有办法可以使1和10在键盘上输入的时候区分开来?
解决方案 »
- 大侠帮忙逐行给我解释下这段代码的意思
- jquery合并单元格问题,求教。
- javascript执行跳转却无法中止以下的PHP程序执行.
- 下面的代码是一个页面显示的倒计时器,我们让让一个页面显示 2个同一个 倒计时器 呀
- 急!JS W3C高手你在何方!!!720°冰天雪地跪求解决方法...
- JS新手问题
- 从下拉菜单选择后把对应的多个值分别填充到多个文本框中
- 可编辑下拉菜单出现乱码,不知道怎么解决
- 在input里输入一字符串,然后要让select下拉框里的选项按此排序,请教怎么实现???
- footerFormatter中如果return的值包含'.'就不显示怎么办
- 怎么样可以点击一个链接展开他的菜单项,点击其他的链接收回这些菜单项?
- 请教ie中event的使用问题。多谢!
可以把Text10换成Text0,
keyCode==95要不按了数字再按回车去确定~~~
用一个数组去记录之前按过什么~~~`回车以后检查数组,检查完以后再清空数组~~
<head>
<title>键盘控制兼容IE6和FF</title>
<script language="javascript" type="text/javascript">
var KC = {
oldk : -1,
timer : 0,
change : function (n) {
KC.timer = 0;
if (n == -1) return;
var o = eval("Text" + n);
o.value += n;
o.focus();
}
};
document.onkeydown = function (event) {
var e = window.event || event;
var c = e.keyCode || e.which;
var n = c - 96;
if (c > 95 && c < 106) {
if (KC.timer == 0) {
KC.oldk = n;
KC.timer = setTimeout("KC.change(" + KC.oldk + ")", 500);
} else if (KC.oldk == 1 && n == 0) {
window.clearTimeout(KC.timer);
KC.oldk = 10;
KC.change(KC.oldk);
} else {
window.clearTimeout(KC.timer);
KC.change(KC.oldk);
KC.oldk = n;
KC.timer = setTimeout("KC.change(" + KC.oldk + ")", 500);
}
return false;
}
}
</script>
</head>
<body>
<input id="Text0" type="text" />
<input id="Text1" type="text" />
<input id="Text2" type="text" />
<input id="Text3" type="text" />
<br />
<input id="Text4" type="text" />
<input id="Text5" type="text" />
<input id="Text6" type="text" />
<input id="Text7" type="text" />
<br />
<input id="Text8" type="text" />
<input id="Text9" type="text" />
<input id="Text10" type="text" />
</body>
</html>
因为Opera不支持那个return false;
如果要解决还需要判断当前焦点。。
这样的话,就麻烦了。。
<script language="javascript" type="text/javascript">
var KC = {
oldk : -1,
timer : 0,
num : (/Opera/.test(window.navigator.userAgent) ? 48 : 96),
change : function (n) {
KC.timer = 0;
if (n == -1) return;
var o = eval("Text" + n);
o.value += n;
o.focus();
}
};
document.onkeydown = function (event) {
var e = window.event || event;
var c = e.keyCode || e.which;
var n = c - KC.num;
if (c > KC.num - 1 && c < KC.num + 10) {
if (KC.timer == 0) {
KC.oldk = n;
KC.timer = setTimeout("KC.change(" + KC.oldk + ")", 500);
} else if (KC.oldk == 1 && n == 0) {
window.clearTimeout(KC.timer);
KC.oldk = 10;
KC.change(KC.oldk);
} else {
window.clearTimeout(KC.timer);
KC.change(KC.oldk);
KC.oldk = n;
KC.timer = setTimeout("KC.change(" + KC.oldk + ")", 500);
}
return false;
}
}
</script>