在浏览器里实现类似VB Form的界面控制

发表于:2007-06-30来源:作者:点击数: 标签:
在浏览器里很容易实现类似 VB Form的文本框,按钮等控制 主要用到 keydown,keyup,keypress 等事件 对按键的捕获使用 window 对象的子对象 event 的 keycode 属性 以下代码仅供参考: %@ Language=VBScript % %@# By Chen Kang @# Any Problem please email to @
在浏览器里很容易实现类似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>

原文转自:http://www.ltesting.net