按下Enter焦點移至下一個控件的實現(xiàn)js代碼
更新時間:2013年12月11日 17:03:36 作者:
正如標(biāo)題所言使用js操作按下Enter焦點移至下一個控件,具體的實現(xiàn)示例如下,需要的朋友可以參考下
復(fù)制代碼 代碼如下:
<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);
}
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>
相關(guān)文章
nullJavascript中創(chuàng)建對象的五種方法實例
今天上午,非常郁悶,有很多簡單基礎(chǔ)的問題搞得我有些迷茫,哎,代碼幾天不寫就忘。目前又不當(dāng)COO,還是得用心記代碼哦!2013-05-05修改layui的后臺模板的左側(cè)導(dǎo)航欄可以伸縮的方法
今天小編就為大家分享一篇修改layui的后臺模板的左側(cè)導(dǎo)航欄可以伸縮的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-09-09