浙林龙哥

   :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

两段用Enter实现tab的功能的代码

2004-11-21 23:12:01 (文章类别:JavaScript)

1 ------------
<script language="javascript">
function document.onkeypress()
{
var eSrc = window.event.srcElement;
if (eSrc.tagName == "INPUT" && eSrc.type == "text" && window.event.keyCode == 13)
{
var inputs = document.all.tags("INPUT");
for (var i= 0; i < inputs.length; i++)
{
if (inputs[i].type == "text" && inputs[i].sourceIndex > eSrc.sourceIndex)
break;
}
if (i <inputs.length)
inputs[i].focus();
}
}
</script>

2 -------------------------------
<%
sSql = "Select * From tablename"
Set rs = Server.CreateObject("ADODB.RecordSet")
rs.Open sSql, conn, 3, 3
%>

<script language="javascript">
function handleKey() {
var next;
if (window.event.keyCode == 13) {
if (window.event.srcElement.index <> "") {
next = (parseInt(window.event.srcElement.index) + 1) + "";
document.all(next).focus();
}
}
}
</script>
<body onkeypress="handleKey()" onload="document.formname.text1.focus()">
<form name="formname">
<%
Dim i
i = 0
while not rs.eof
%>
<input type="text" name=rs("user_id") index="<%= i %>"><br>
<%
rs.movenext
wend
%>
</form>
</body>
posted on 2004-12-06 17:44  浙林龙哥  阅读(2068)  评论(2编辑  收藏  举报