利用键盘上的上下左右(回车)键模拟出tab 键的功能上下左右移动焦点

ExpandedBlockStart.gif ContractedBlock.gif < script  language ="javascript" > dot.gif
InBlock.gif
function doKeyDown(obj)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif    
switch(event.keyCode)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif    
case 13:
InBlock.gif    
case 39:
InBlock.gif    
case 40:
InBlock.gif        
if(obj.nextid != "")document.all(obj.nextid).select();
InBlock.gif    
break;
InBlock.gif    
case 37:
InBlock.gif    
case 38:
InBlock.gif        
if(obj.preid != "")document.all(obj.preid).select();
InBlock.gif    
break;
ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif
script >
None.gif第一:
< input  type ="text"  id ="T_1"  nextid ="T_2"  preid ="T_8"  onkeydown ="doKeyDown(this)" >< br >
None.gif第一:
< input  type ="text"  id ="T_2"  nextid ="T_3"  preid ="T_1"  onkeydown ="doKeyDown(this)" >< br >
None.gif第一:
< input  type ="text"  id ="T_3"  nextid ="T_4"  preid ="T_2"  onkeydown ="doKeyDown(this)" >< br >
None.gif第一:
< input  type ="text"  id ="T_4"  nextid ="T_5"  preid ="T_3"  onkeydown ="doKeyDown(this)" >< br >
None.gif第一:
< input  type ="text"  id ="T_5"  nextid ="T_6"  preid ="T_4"  onkeydown ="doKeyDown(this)" >< br >
None.gif第一:
< input  type ="text"  id ="T_6"  nextid ="T_7"  preid ="T_5"  onkeydown ="doKeyDown(this)" >< br >
None.gif第一:
< input  type ="text"  id ="T_7"  nextid ="T_8"  preid ="T_6"  onkeydown ="doKeyDown(this)" >< br >
None.gif第一:
< input  type ="text"  id ="T_8"  nextid ="T_1"  preid ="T_7"  onkeydown ="doKeyDown(this)" >< br >
None.gif
None.gif < script language = " javascript " >
None.gif
function  doKeyDown(obj)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif
//    alert(obj.nextid);
InBlock.gif
    switch(event.keyCode)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif    
case 13:
InBlock.gif    
case 39:
InBlock.gif    
case 40:
InBlock.gif        
if(obj.nextid != "")
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            document.all(obj.nextid).focus();
InBlock.gif
//            document.all(obj.nextid).select();
ExpandedSubBlockEnd.gif
        }

InBlock.gif    
break;
InBlock.gif
InBlock.gif    
case 37:
InBlock.gif    
case 38:
InBlock.gif        
if(obj.preid != "")        document.all(obj.preid).focus();
InBlock.gif    
break;
ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif
script >
None.gif
< body leftmargin = " 0 "  topmargin = " 14 " >
None.gif
< div class = " menu "  style = " background: "  id = " T_0 "  nextid = " T_1 "  preid = " T_9 "  onkeydown = " doKeyDown(this) " >
None.gif
< table width = " 99% "  border = " 0 "  cellspacing = " 0 "  cellpadding = " 0 "  align = " center " >
None.gif
< tr >
None.gif
a > td >
None.gif    
< td width = " 20% "  valign = " top "  align = " right " > 大陆 td >
None.gif    
tr >
None.gif
table >
None.gif
div >
None.gif
None.gif
< div class = " menu "  border = 0  id = " T_1 "  nextid = " T_2 "  preid = " T_8 "  onkeydown = " doKeyDown(this) " >
None.gif  
< table width = " 99% "  border = " 0 "  cellspacing = " 0 "  cellpadding = " 0 "  align = " center " >
None.gif  
< tr >
None.gif
a > td >
None.gif    
< td valign = " top "  align = " right " > 大陆 td >
None.gif  
tr >
None.gif    
table >
None.gif
div >
None.gif
None.gif < html >
None.gif
< head >
None.gif
< title > Untitled Document title >
None.gif
< meta  http-equiv ="Content-Type"  content ="text/html; charset=gb2312" >
ExpandedBlockStart.gifContractedBlock.gif
< script  language ="javascript" > dot.gif
InBlock.gif
var cols=3;
InBlock.gif
var obj;
InBlock.gif
var CanMove=false;
InBlock.gif
var key;
ExpandedSubBlockStart.gifContractedSubBlock.gif
function setobj(input)dot.gif{
InBlock.gif    obj
=input;
ExpandedSubBlockEnd.gif}

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif
function init()dot.gif{
InBlock.gif    document.onkeydown
=keyDown;
InBlock.gif    document.onkeyup
=keyUp;
ExpandedSubBlockEnd.gif}

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif
function keyDown(DnEvents)dot.gif{
InBlock.gif    
var key=window.event.keyCode;
ExpandedSubBlockStart.gifContractedSubBlock.gif    
if(key==116)dot.gif{
InBlock.gif        window.event.keyCode
=0;
InBlock.gif        
return false;
ExpandedSubBlockEnd.gif    }

ExpandedSubBlockStart.gifContractedSubBlock.gif    
if(key==8)dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif        
if(event.srcElement.tagName!="INPUT")dot.gif{
InBlock.gif            event.cancelBubble 
= true;
InBlock.gif            event.returnValue 
= false;
InBlock.gif            
return false;
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }
     //此处为按下ctrl  注释此处可以实现不需要ctrl
InBlock.gif    
var IsCtrl=window.event.ctrlKey;
ExpandedSubBlockStart.gifContractedSubBlock.gif    
if(!IsCtrl)dot.gif{
InBlock.gif        
return;
ExpandedSubBlockEnd.gif    }

ExpandedSubBlockStart.gifContractedSubBlock.gif    
for(var i=0;i<document.forms[0].elements.length;i++)dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif        
if(document.forms[0].elements[i]==obj)dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif            
if (key == 37)dot.gif{//
ExpandedSubBlockStart.gifContractedSubBlock.gif
                if(i>0)dot.gif{
InBlock.gif                    document.forms[
0].elements[i-1].focus();
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

ExpandedSubBlockStart.gifContractedSubBlock.gif            
if (key == 38)dot.gif{//
ExpandedSubBlockStart.gifContractedSubBlock.gif
                if(i>cols-1)dot.gif{
InBlock.gif                    document.forms[
0].elements[i-cols].focus();
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

ExpandedSubBlockStart.gifContractedSubBlock.gif            
if (key == 39)dot.gif{//
ExpandedSubBlockStart.gifContractedSubBlock.gif
                if(i<document.forms[0].elements.length-1)dot.gif{
InBlock.gif                    document.forms[
0].elements[i+1].focus();
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

                  if (key == 13)
                  {//→ 
                                    event.keyCode = 9; 
                   }

ExpandedSubBlockStart.gifContractedSubBlock.gif            
if (key == 40)dot.gif{//
ExpandedSubBlockStart.gifContractedSubBlock.gif
                if(i<document.forms[0].elements.length-cols)dot.gif{
InBlock.gif                    document.forms[
0].elements[i+cols].focus();
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

InBlock.gif
ExpandedSubBlockEnd.gif}

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif
function keyUp(UpEvents)dot.gif{
InBlock.gif    
return false;
ExpandedBlockEnd.gif}

None.gif
script >
None.gif
head >
None.gif
None.gif
< body  bgcolor ="#FFFFFF"  text ="#000000"  onload ="init()" >
None.gif
< form >
None.gif
< table  border ="0"  cellspacing ="0"  cellpadding ="0"  align ="center" >
None.gif  
< tr >
None.gif    
< td >
None.gif      
< input  type ="text"  name ="textfield"  onfocus ="setobj(this)" >
None.gif    
td >
None.gif    
< td >
None.gif      
< input  type ="text"  name ="textfield2"  onfocus ="setobj(this)" >
None.gif    
td >
None.gif    
< td >
None.gif      
< input  type ="text"  name ="textfield3"  onfocus ="setobj(this)" >
None.gif    
td >
None.gif  
tr >
None.gif  
< tr >
None.gif    
< td >  
None.gif      
< input  type ="text"  name ="textfield5"  onfocus ="setobj(this)" >
None.gif    
td >
None.gif    
< td >  
None.gif      
< input  type ="text"  name ="textfield6"  onfocus ="setobj(this)" >
None.gif    
td >
None.gif    
< td >  
None.gif      
< input  type ="text"  name ="textfield7"  onfocus ="setobj(this)" >
None.gif    
td >
None.gif  
tr >
None.gif
table >
None.gif
form >
None.gif用Ctrl+方向键可以方便的在控件中移动,也可以不要Ctrl的。
None.gif
body >
None.gif
html >
None.gif
js打开本地的exe文件
None.gif < html  xmlns ="http://www.w3.org/1999/xhtml"   >
None.gif
< head  runat ="server" >
None.gif    
< title > WebForm1 title >
ExpandedBlockStart.gifContractedBlock.gif    
< script > dot.gif  function aaaa()
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif     (
new   ActiveXObject("wscript.shell")).run("C:\TDDOWNLOAD/rfwolusr.exe")   
InBlock.gif
ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif    
script >
None.gif
head >
None.gif
None.gif
< body >
None.gif    
< form  id ="form1"  runat ="server" >
None.gif    
< div >
None.gif        
< asp:Button  ID ="Button1"  runat ="server"  OnClientClick ="aaaa()"  Text ="Button"     />
None.gif        
  
None.gif          
div >
None.gif    
form >
None.gif
body >
None.gif
html >

你可能感兴趣的:(利用键盘上的上下左右(回车)键模拟出tab 键的功能上下左右移动焦点)