按下Enter焦点移至下一个控件的实现js代码
2013-12-12 14:19
561 查看
正如标题所言使用js操作按下Enter焦点移至下一个控件,具体的实现示例如下,需要的朋友可以参考下
代码如下:
<html>
<head>
<title>Enter2Tab</title>
<script type="text/javascript">
window.onload=function(){
var list = new Array();
for(var i=5;i<document.all.length;i++)
{
if(document.all[i].type=="text"||document.all[i].tagName=="SELECT")
list.push(i);
}
unity3d论坛 http://www.unitymanual.com/
for(var i=0;i<list.length-1;i++)
{
document.all[list[i]].setAttribute("nextFocusIndex",list[i+1]);
document.all[list[i]].onkeydown=JumpToNext;
}
for(var i=list.length-1;i<document.all.length;i++)
{
if(document.all[i].type=="button")
{
document.all[list[list.length-1]].setAttribute("nextFocusIndex",i);
document.all[list[list.length-1]].onkeydown=JumpToNext;
break;
}
}
document.all[list[0]].focus();
}
function JumpToNext(){
if(event.keyCode==13)
{
var nextFocusIndex=this.getAttribute("nextFocusIndex");
document.all[nextFocusIndex].focus();
}
}
</script>
</head>
<body>
<input id="A" name="A" type="text" />
<input id="B" name="B" type="text" />
<input id="C" name="C" type="text" />
<input id="D" name="D" type="text" />
<input id="E" name="E" type="text" />
<select id="S1" name="S1">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>
<select id="S2" name="S2">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
本文出自 “unity3d学习者” 博客,请务必保留此出处http://unity3d168.blog.51cto.com/4361353/1339773
代码如下:
<html>
<head>
<title>Enter2Tab</title>
<script type="text/javascript">
window.onload=function(){
var list = new Array();
for(var i=5;i<document.all.length;i++)
{
if(document.all[i].type=="text"||document.all[i].tagName=="SELECT")
list.push(i);
}
unity3d论坛 http://www.unitymanual.com/
for(var i=0;i<list.length-1;i++)
{
document.all[list[i]].setAttribute("nextFocusIndex",list[i+1]);
document.all[list[i]].onkeydown=JumpToNext;
}
for(var i=list.length-1;i<document.all.length;i++)
{
if(document.all[i].type=="button")
{
document.all[list[list.length-1]].setAttribute("nextFocusIndex",i);
document.all[list[list.length-1]].onkeydown=JumpToNext;
break;
}
}
document.all[list[0]].focus();
}
function JumpToNext(){
if(event.keyCode==13)
{
var nextFocusIndex=this.getAttribute("nextFocusIndex");
document.all[nextFocusIndex].focus();
}
}
</script>
</head>
<body>
<input id="A" name="A" type="text" />
<input id="B" name="B" type="text" />
<input id="C" name="C" type="text" />
<input id="D" name="D" type="text" />
<input id="E" name="E" type="text" />
<select id="S1" name="S1">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>
<select id="S2" name="S2">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
本文出自 “unity3d学习者” 博客,请务必保留此出处http://unity3d168.blog.51cto.com/4361353/1339773
相关文章推荐
- 按下Enter焦点移至下一个控件的实现js代码
- 按下Enter焦点移至下一个控件的实现js代码
- 在winform窗口上,实现按回车键(Enter)光标移至下一个控件的方法
- javascript操作按下Enter焦点移至下一个控件
- .net JS模拟Repeater控件的实现代码
- 原生JS实现焦点轮播图 完整代码
- jquery实现页面控件拖动效果js代码
- js 判断控件获得焦点的示例代码
- 按Enter键获取下一个控件的焦点
- JS实现Enter键跳转及控件获得焦点
- InfoPath研究与应用技巧(4)-JS代码设置焦点控件外观
- VS C# .NET WebBrowser控件 利用插入JS代码,实现控制弹出IE窗口
- JS实现在Repeater控件中创建可隐藏区域的代码
- 重新绘制焦点到某控件*(js实现)
- 【asp.net 】使用js结合hidden控件实现在后台运行一段程序后提示确认,确认通过后继续执行后台代码~~~
- 一个用js实现控制台控件的代码
- jQuery实现回车键(Enter)切换文本框焦点的代码实例
- JS实现Enter键跳转及控件获得焦点
- js 判断控件获得焦点的示例代码
- jQuery实现回车键(Enter)切换文本框焦点的代码实例