日期:2014-05-16  浏览次数:20425 次

文件框select()问题?用上下键就不能全选文字,为什么?单击没问题!
<html>
<head>
<meta   http-equiv= "Content-Type "   content= "text/html;   charset=utf-8 ">
<title> test </title>
<script   type= "text/javascript ">
function   move_inp(i,n,s,a){
keycode=event.keyCode;//focus(),down   40,up   38
if(keycode==40){n=n+1;}else   if(keycode==38){n=n-1;}
if(n <a&&n> =s){eval( "document.all. "+i+ " "+n).focus();eval( "document.all. "+i+ " "+n).select();}
}
</script>
</head>

<body>
<input   onKeyDown= "move_inp( 'a ',0,0,10) "   id= "a0 "   name= " "   value= "dad "   type= "text "   onClick= "this.select(); "> <br>
<input   onKeyDown= "move_inp( 'a ',1,0,10) "   id= "a1 "   name= " "   value= "dad "   type= "text "   onClick= "this.select(); "> <br>
<input   onKeyDown= "move_inp( 'a ',2,0,10) "   id= "a2 "   name= " "   value= "dad "   type= "text "   onClick= "this.select(); "> <br>
<input   onKeyDown= "move_inp( 'a ',3,0,10) "   id= "a3 "   name= " "   value= "dad "   type= "text "   onClick= "this.select(); "> <br>
<input   onKeyDown= "move_inp( 'a ',4,0,10) "   id= "a4 "   name= " "   value= "dad "   type= "text "   onClick= "this.select(); "> <br>
<input   onKeyDown= "move_inp( 'a ',5,0,10) "   id= "a5 "   name= " "   value= "dad "   type= "text "   onClick= "this.select(); "> <br>
<input   onKeyDown= "move_inp( 'a ',6,0,10) "   id= "a6 "   name= " "   value= "dad "   type= "text "   onClick= "this.select(); "> <br>
<input   onKeyDown= "move_inp( 'a ',7,0,10) "   id= "a7 "   name= " "   value= "dad "   type= "text "   onClick= "this.select(); "> <br>
<input   onKeyDown= "move_inp( 'a ',8,0,10) "   id= "a8 "   name= " "   value= "dad "   type= "text "   onClick= "this.select(); "> <br>
<input   onKeyDown= "move_inp( 'a ',9,0,10) "   id= "a9 "   name= " "   value= "dad "   type= "text "   onClick= "this.select(); "> <br>
</body>
</html>


------解决方案--------------------
function move_inp(i,n,s,a){
keycode=event.keyCode;//focus(),down 40,up 38
if(keycode==40 || keycode==38)
{

n= keycode==40?n+1:n-1;
if(n <a &&n > = s)
{

eval( "document.all. "+i+ " "+n).focus();
eval( "document.all. "+i+ " "+n).select();
event.returnValue=false;
}
}
}
------解决方案--------------------
要自动选择。设置onfocus= "this.select() "