请教众多高手都未解决--用键盘控制鼠标光标的位置,急!!!!!!!!!!
高手都哪儿去了?我要的效果是,每按一次箭头键,光标只移动一个单元格,我的表格是动态生成的,每一个单元格都是一个文本械,有关代码如下:
<% for i=1 to request.form( "num ") %>
<table width= "613 " border= "0 " cellspacing= "0 " cellpadding= "0 " height= "8 " align= "center ">
<tr>
<td width= "77 " height= "6 ">
<div align= "left "> <font size= "2 ">
<input type= "text " name= "testnumber <%=i%> " size= "11 " style= "border: 1pt solid #EEEEEE;background-color:transparent " maxlength= "15 ">
</font> </div>
</td>
<td width= "70 " height= "6 ">
<div align= "left "> <font size= "2 ">
<input type= "text " name= "name <%=i%> " size= "8 " style= "border: 1pt solid #EEEEEE;background-color:transparent ">
</font> </div>
</td>
<td width= "50 " height= "6 ">
<div align= "center "> <font size= "2 ">
<input type= "text " name= "language <%=i%> " size= "6 " style= "border: 1pt solid #EEEEEE;background-color:transparent " maxlength= "3 ">
</font> </div>
</td>
<td width= "56 " height= "6 ">
<div align= "center "> <font size= "2 ">
<input type= "text " name= "mathe <%=i%> " size= "6 " style= "border: 1pt solid #EEEEEE;background-color:transparent " maxlength= "3 ">
</font> </div>
</td>
<td width= "45 " height= "6 ">
<div align= "center "> <font size= "2 ">
<input type= "text " name= "english <%=i%> " size= "6 "style= "border: 1pt solid #EEEEEE;background-color:transparent " maxlength= "3 " >
</font> </div>
</td>
<% next %>
[解决办法]
和你要点RMB呀?给不?哈哈
昨天让一个SB气着了,今天让你实惠一下
<html>
<head>
<title> Untitled Document </title>
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 ">
<style type= "text/css ">
<!--
td { font-family: "Verdana ", "Arial ", "Helvetica ", "sans-serif "; font-size: 8pt}
input { font-family: "Verdana ", "Arial ", "Helvetica ", "sans-serif "; font-size: 8pt}
body { font-family: "Verdana ", "Arial ", "Helvetica ", "sans-serif "; font-size: 8pt}
-->
</style>
</head>
<body bgcolor= "#FFFFFF ">
<script language= "javascript ">
<!--
//==============
//方向键控制
//==============
var obj;
var rowth;
var fieldNum =2; //栏数
//var objID;
//var blnMove=false;
function setobj(input,rowths) {
obj = input;
// objID = parseInt(obj.id);
rowth = parseInt(rowths);
}
function document.onkeydown(url) {
with(window.event){
with(srcElement){
objID = parseInt(id);
if (keyCode == 37 && obj) {//←
var s=document.selection.createRange(); //s.setEndPoint( "StartToEnd ",obj.createTextRange())
if(obj.tagName!= "SELECT ") s.setEndPoint( "StartToStart ",obj.createTextRange()); //select不支持此方法
if (s.text== " " || obj.tagName== "SELECT ") { //到达字符串开头,光标跳到前一个元素 ||obj.tagName== "SELECT "
if (document.all.item((objID - 1).toString(),rowth) && objID> 0) {
document.all.item((objID - 1).toString(),rowth).focus();
if(document.all.item((objID - 1).toString(),rowth).tagName!= "SELECT ") document.all.item((objID - 1).toString(),rowth).select();
} else if (document.all.item((fieldNum-1).toString(),rowth-1) && rowth> 0 && objID==0) {
document.all.item((fieldNum-1).toString(),rowth-1).focus();
if(document.all.item((fieldNum-1).toString(),rowth-1).tagName!= "SELECT ") document.all.item((fieldNum-1).toString(),rowth-1).select();
}
}
} else if (keyCode == 38 && obj && rowth> 0) {//↑
if (document.all.item(objID.toString(),rowth-1)) {
if (document.all.item(objID.toString(),rowth-1).tagName!= "SELECT ") { //对于选择列,上下聚焦会自动变更选择值
document.all.item(objID.toString(),rowth-1).focus();
document.all.item(objID.toString(),rowth-1).select();
}
}
} else if (keyCode == 39 && obj) {//→
var s = document.selection.createRange();
if(obj.tagName!= "SELECT ") s.setEndPoint( "StartToEnd ",obj.createTextRange()); //select不支持此方法
if (s.text== " " || obj.tagName== "SELECT ") { //到达字符串最末,光标跳到后一个元素 ||obj.tagName== "SELECT "
if (document.all.item((objID + 1).toString(),rowth)) {
document.all.item((objID + 1).toString(),rowth).focus();
if(document.all.item((objID + 1).toString(),rowth).tagName!= "SELECT ") document.all.item((objID + 1).toString(),rowth).select();
} else if (document.all.item( '0 ',rowth+1)) {
document.all.item( '0 ',rowth+1).focus();
if(document.all.item( '0 ',rowth+1).tagName!= "SELECT ") document.all.item( '0 ',rowth+1).select();
}
}
} else if (keyCode == 40 && obj) {//↓
if (document.all.item(objID.toString(),rowth+1)) {
if (document.all.item(objID.toString(),rowth+1).tagName!= "SELECT ") {
document.all.item(objID.toString(),rowth+1).focus();
document.all.item(objID.toString(),rowth+1).select();
} }
} else {
return true;
}
}}
}
//-->
</script>
<body bgcolor= "#FFFFFF " topmargin= "30 " leftmargin= "150 ">
<div disabled> <b>
QQ:37389402 <br>
MSN:service@autd.net <br>
http://www.autd.net <br> <br> <br> <br>
</div>
<% for i=1 to 5 %>
<table width= "613 " border= "0 " cellspacing= "0 " cellpadding= "0 " height= "8 " >
<tr>
<td width= "77 " height= "6 ">
<div align= "left "> <font size= "2 ">
<input type= "text " id= '0 ' name= "testnumber <%=i%> " size= "10 " style= "border: 1pt solid #cccccc;background-color:transparent " maxlength= "15 " onFocus= 'setobj(this,0) ' >
</font> </div>
</td>
<td width= "70 " height= "6 ">
<div align= "left "> <font size= "2 ">
<input type= "text " id= '1 ' name= "name <%=i%> " size= "10 " style= "border: 1pt solid #cccccc;background-color:transparent " onFocus= 'setobj(this,0) '>
</font> </div>
</td>
<td width= "50 " height= "6 ">
<div align= "center "> <font size= "2 ">
<input type= "text " id= '2 ' name= "language <%=i%> " size= "10 " style= "border: 1pt solid #cccccc;background-color:transparent " maxlength= "3 " onFocus= 'setobj(this,0) '>
</font> </div>
</td>
<td width= "56 " height= "6 ">
<div align= "center "> <font size= "2 ">
<input type= "text " id= '3 ' name= "mathe <%=i%> " size= "10 " style= "border: 1pt solid #cccccc;background-color:transparent " maxlength= "3 " onFocus= 'setobj(this,0) '>
</font> </div>
</td>
<td width= "45 " height= "6 ">
<div align= "center "> <font size= "2 ">
<input type= "text " id= '4 ' name= "english <%=i%> " size= "10 "style= "border: 1pt solid #cccccc;background-color:transparent " maxlength= "3 " onFocus= 'setobj(this,0) '>
</font> </div>
</td>
</tr>
</table>
<% next %>
</body>
</html>
基于你的代码和http://community.csdn.net/Expert/TopicView3.asp?id=5331598页面代码整合
QQ:37389402
MSN:service@autd.net
http://www.autd.net
[解决办法]
说明:代码有错漏的地方:
1.没有用到 <form> </form> 定义表单,不能引用表单名
2.用for 语句生成多个表单,等到的多个重名控件,不能区分
以下是实现按下enter建光标移动至下一输入域的代码,其实与按tab键的功能无什么区别,仅供参考。。
<html>
<head>
<script language = "VbScript ">
<!--
'加载事件
sub window_onload
form1.testnumber1.focus
end sub
dim i
i=1
,testnumber事件
sub Form(i).testnumber_onkeypress
if window.event.keycode = 13 then
Form(i).name.focus
end if
end sub
sub Form(i).name_onkeypress
if window.event.keycode = 13 then
Form(i).language.focus
end if
end sub
sub Form(i).language_onkeypress
if window.event.keycode =13 then
Form(i).mathe.focus
end if
end sub
sub Form(i).mathe_onkeypress
if window.event.keycode =13 then
Form(i).english.focus
end if
'移至下一表格
if i < request.form( "num ") then
i=i+1
end if
end sub
--〉
</script>
</head>
<body>
<% for i=1 to request.form( "num ") %>
<form name = "form <&=i&> " method = " " action = " ">
<table width= "613 " border= "0 " cellspacing= "0 " cellpadding= "0 " height= "8 " align= "center ">
<tr>
<td width= "77 " height= "6 ">
<div align= "left "> <font size= "2 ">
<input type= "text " name= "testnumber " size= "11 " style= "border: 1pt solid #EEEEEE;background-color:transparent " maxlength= "15 ">
</font> </div>
</td>
<td width= "70 " height= "6 ">
<div align= "left "> <font size= "2 ">
<input type= "text " name= "name " size= "8 " style= "border: 1pt solid #EEEEEE;background-color:transparent ">
</font> </div>
</td>
<td width= "50 " height= "6 ">
<div align= "center "> <font size= "2 ">
<input type= "text " name= "language " size= "6 " style= "border: 1pt solid #EEEEEE;background-color:transparent " maxlength= "3 ">
</font> </div>
</td>
<td width= "56 " height= "6 ">
<div align= "center "> <font size= "2 ">
<input type= "text " name= "mathe " size= "6 " style= "border: 1pt solid #EEEEEE;background-color:transparent " maxlength= "3 ">
</font> </div>
</td>
<td width= "45 " height= "6 ">
<div align= "center "> <font size= "2 ">
<input type= "text " name= "english " size= "6 "style= "border: 1pt solid #EEEEEE;background-color:transparent " maxlength= "3 " >
</font> </div>
</td> </table>
</form>
<% next %>
</body>
</html>
[解决办法]
说明:代码有错漏的地方:
1.没有用到 <form> </form> 定义表单,不能引用表单名
2.用for 语句生成多个表单,等到的多个重名控件,不能区分
以下是实现按下enter建光标移动至下一输入域的代码,其实与按tab键的功能无什么区别,仅供参考。。
<html>
<head>
<script language = "VbScript ">
<!--
'加载事件
sub window_onload
form1.testnumber.focus
end sub
dim i
i=1
,testnumber事件
sub Form(i).testnumber_onkeypress
if window.event.keycode = 13 then
Form(i).name.focus
end if
end sub
sub Form(i).name_onkeypress
if window.event.keycode = 13 then
Form(i).language.focus
end if
end sub
sub Form(i).language_onkeypress
if window.event.keycode =13 then
Form(i).mathe.focus
end if
end sub
sub Form(i).mathe_onkeypress
if window.event.keycode =13 then
Form(i).english.focus
end if
'移至下一表格
if i < request.form( "num ") then
i=i+1
'上面漏了
Form(i).testnumber.focus
end if
end sub
--〉
</script>
</head>
<body>
<% for i=1 to request.form( "num ") %>
<form name = "form <&=i&> " method = " " action = " ">
<table width= "613 " border= "0 " cellspacing= "0 " cellpadding= "0 " height= "8 " align= "center ">
<tr>
<td width= "77 " height= "6 ">
<div align= "left "> <font size= "2 ">
<input type= "text " name= "testnumber " size= "11 " style= "border: 1pt solid #EEEEEE;background-color:transparent " maxlength= "15 ">
</font> </div>
</td>
<td width= "70 " height= "6 ">
<div align= "left "> <font size= "2 ">
<input type= "text " name= "name " size= "8 " style= "border: 1pt solid #EEEEEE;background-color:transparent ">
</font> </div>
</td>
<td width= "50 " height= "6 ">
<div align= "center "> <font size= "2 ">
<input type= "text " name= "language " size= "6 " style= "border: 1pt solid #EEEEEE;background-color:transparent " maxlength= "3 ">
</font> </div>
</td>
<td width= "56 " height= "6 ">
<div align= "center "> <font size= "2 ">
<input type= "text " name= "mathe " size= "6 " style= "border: 1pt solid #EEEEEE;background-color:transparent " maxlength= "3 ">
</font> </div>
</td>
<td width= "45 " height= "6 ">
<div align= "center "> <font size= "2 ">
<input type= "text " name= "english " size= "6 "style= "border: 1pt solid #EEEEEE;background-color:transparent " maxlength= "3 " >
</font> </div>
</td> </table>
</form>
<% next %>
</body>
</html>