VBScript允许开发人员与用户进行有效的交互。它可以是一个向用户显示消息的消息框,也可以是一个用户可以用来输入值的输入框。
MsgBox函数将显示一个消息框,并等待用户单击按钮,然后根据用户单击的按钮执行操作。
MsgBox(prompt[,buttons][,title][,helpfile,context])
该按钮参数可以采取以下任何值-
以上值在逻辑上分为四组:第一组(0到5)指示要在消息框中显示的按钮。第二组(16、32、48、64)描述了要显示的图标的样式,第三组(0、256、512、768)指示哪个按钮必须是默认按钮,第四组(0、4096) )确定消息框的形式。
MsgBox函数可以返回以下值之一-
<!DOCTYPE html> <html> <body> <script language = "vbscript" type = "text/vbscript"> 'Message Box with just prompt message MsgBox("Welcome") 'Message Box with title, yes no and cancel Butttons a = MsgBox("Do you like blue color?",3,"Choose options") ' Assume that you press No Button document.write("The Value of a is " & a) </script> </body> </html>
执行上述脚本后,将显示消息框,如果按No Button,则a的值为7。
The Value of a is 7
InputBox函数可帮助用户从用户那里获取值。输入值后,如果用户单击“确定”按钮或按键盘上的ENTER键,InputBox函数将在文本框中返回文本。如果用户单击“取消”按钮,该函数将返回一个空字符串(“”)。
InputBox(prompt[,title][,default][,xpos][,ypos][,helpfile,context])
<!DOCTYPE html>
<html>
<body>
<script language = "vbscript" type = "text/vbscript">
' Input Box with only Prompt
InputBox("Enter a number")
' Input Box with a Title
a = InputBox("Enter a Number","Enter Value")
msgbox a
' Input Box with a Prompt,Title and Default value
a = InputBox("Enter a Number","Enter Value",123)
msgbox a
' Input Box with a Prompt,Title,Default and XPos
a = InputBox("Enter your name","Enter Value",123,700)
msgbox a
' Input Box with a Prompt,Title and Default and YPos
a = InputBox("Enter your name","Enter Value",123,,500)
msgbox a
</script>
</body>
</html>
执行上述脚本后,将显示输入框,并由用户显示输入的值。