在浏览器里很容易实现类似vb form的文本框,按钮等控制
主要用到 keydown,keyup,keypress 等事件
对按键的捕获使用 window 对象的子对象 event 的 keycode 属性
以下代码仅供参考:
<%@ language=vbscript %>
<% by chen kang
any problem please email to
chenkang@chenkang.com
vi 6.0 scripting object model enabled %>
<!–#include file="_scriptlibrary/pm.asp"–>
<% if startpageprocessing() then response.end() %>
<form name=thisform method=post>
<html>
<head>
<meta name=vi60_dtcscriptingplatform content="client (ie 4.0 dhtml)">
<meta name=vi60_defaultclientscript content=vbscript>
<meta name="generator" content="microsoft visual studio 6.0">
</head>
<body>
<script id=clienteventhandlersvbs language=vbscript>
<!–
sub btnok_onclick()
dim rtnvalue
set rtnvalue = logon.execute.checkpasswd(thisform.txtuserid.value,thisform.txtpasswd.value)
select case rtnvalue.return_value
case 0
密码正确,转其他程序
blahlah
case 1
msgbox("登录号错误,请重新输入!")
set highlight
set highlight = thisform.txtuserid.createtextrange
highlight.select
set focus
thisform.txtuserid.focus
case 2
msgbox("密码错误,请重新输入!")
set highlight = thisform.txtpasswd.createtextrange
highlight.select
thisform.txtpasswd.focus
case 3
msgbox("该用户已在别的工作站登录,请重新输入!")
set highlight = thisform.txtpasswd.createtextrange
highlight.select
thisform.txtpasswd.focus
end select
end sub
sub txtuserid_onkeyup()
如果是回车键或下箭头
if window.event.keycode=13 or window.event.keycode=40 then
set highlight = thisform.txtpasswd.createtextrange
highlight.select
thisform.txtpasswd.focus
end if
end sub
sub txtpasswd_onkeyup()
if window.event.keycode=13 or window.event.keycode=40 then
thisform.btnok.focus
end if
如果是上箭头
if window.event.keycode=38 then
set highlight = thisform.txtuserid.createtextrange
highlight.select
thisform.txtuserid.focus
end if
end sub
sub window_onload
thisform.txtuserid.focus
end sub
–>
</script>
<p align=center>操作员登录号:
<input id=txtuserid name=txtuserid maxlength=2 style="height: 21px; width: 142px">
<br>
操作员 密码:
<input id=txtpasswd name=txtpasswd maxlength=4 style="height: 21px; width: 142px" type=password>
<br>
</p>
<p align=center>
<input id=btnok name=btnok align=center type=button value="确认" style="color: darkslategray; font-size: larger; font-style: normal; font-weight: bold; height: 35px; width: 86px">
</p>
</body>
<% vi 6.0 scripting object model enabled %>
<% endpageprocessing() %>
</form>
</html>
