set oIE = WScript.CreateObject("InternetExplorer.Application","Event_")
With oIE
.MenuBar = 0
.StatusBar = 0
.AddressBar = 0
.ToolBar = 0
.Height = 150
.Width = 200
.Navigate "about:blank"
.Visible = 1
.Document.Write "<HTML><BODY scroll='no'><input id='input1'><br>"
.Document.Write "<input id='input2'><br><input id='input3'>"
.Document.Write "<BUTTON id='btn'>确定</BUTTON></BODY></HTML>"
End With
Set oIE.Document.getElementById("btn").OnClick = GetRef("aaa")
Do
WScript.Sleep 200
Loop
Sub aaa
Dim str
str = oIE.Document.getElementById("input1").Value & VbCrLf
str = str & oIE.Document.getElementById("input2").Value & VbCrLf
str = str & oIE.Document.getElementById("input3").Value
WScript.Echo str
End Sub
Sub Event_OnQuit
WScript.Quit
End Sub
写了一个函数 multiInputBox ,可以这样用
WScript.Echo "这个例子是模仿你贴出来的图片"
ss = multiInputBox("实例", "要搜索的文件或文件夹名为:^^M|包含文字:^^C")
WScript.Echo "输入的文件名是:" & ss(0)
WScript.Echo "包含文字是:" & ss(1)
以下是这个函数:
multiInputBox(title, content)
'**************************************************************
'* “VBS多重输入框” (P)&(C) 2010 『据说是李先生』
'*
'* 返回值为一个数组,依次是各个输入值。
'*
'* title : 输入框标题
'*
'* content : 一个字符串,包含显示信息,具体格式为
'*
'* 提示信息^默认值^热键|提示信息^默认值^热键|...
'*
'* “^” 和 “|” 做分隔符,只有提示信息是必需的
'*
'* 热键:一个字符,比如“M”,按住Alt,再按M就能快速定位到此条输入框
'*
'***************************************************************
Function multiInputBox(title, content)
Dim htmlStr, temp, i, l, height, allInputs, input, contentArr(), result()
temp = Split(content, "|")
ReDim contentArr(UBound(temp))
For i = 0 To UBound(temp)
contentArr(i) = Split(temp(i), "^")
Next
l = UBound(contentArr)
ReDim result(l)
height = l * 50 + 155
htmlStr = "<html><head><title>" & title & "</title>"
htmlStr = htmlStr & "<meta http-equiv=content-type content=""text/html; charset=gb18030"">"
htmlStr = htmlStr & "<style type=""text/css"">*{font:12px/1.2em Arial;} .input_box{width:250px;height:23px;padding-top:3px;border-color:#CCC;color:#333;background-color:#EEE;}</style>"
htmlStr = htmlStr & "<script type=""text/javascript"">function cf(e){if(e.altKey)try{eval(String.fromCharCode(e.keyCode)).focus()}catch(e){};}</script>"
htmlStr = htmlStr & "</head><body scroll=""no"" onkeyup=""cf(event)"">"
For i = 0 To l
temp = "<input onfocus=""javascript:this.select();"" class=""input_box"" type=""text"""
If UBound(contentArr(i)) > 0 Then temp = temp & """ value=""" & contentArr(i)(1)
If UBound(contentArr(i)) > 1 Then
temp = temp & """ name=""" & UCase(contentArr(i)(2))
temp = contentArr(i)(0) & "(<u>" & UCase(contentArr(i)(2)) & "</u>)<br>" & temp
Else
temp = contentArr(i)(0) & "<br>" & temp
End If
temp = temp & """ /><br><br>"
htmlStr = htmlStr & temp
Next
htmlStr = htmlStr & "<br><input type=""hidden"" name=""ching"" value=""me""/>"
htmlStr = htmlStr & "<input type=""button"" value=""确定"" onclick=""javascript:ching.value='ching';""/>"
htmlStr = htmlStr & "<input type=""button"" value=""取消"" onclick=""javascript:ching.value='caofackri';""/>"
htmlStr = htmlStr & "</body></html>"
'本来想用UMU在点关闭的时候清空数据,但那样至少要分割成两个函数,因此改用错误忽略。
With WScript.CreateObject("InternetExplorer.Application", "UMU_")
.menubar=0:.addressbar=0:.toolbar=0:.statusbar=0:.resizable=0
.width=300:.height=height:.navigate "about:blank":.visible=1
.document.write htmlStr
Do
On Error Resume Next
WScript.Sleep 100
If .document.body.all.ching.value = "ching" Then
Set allInputs = .document.getElementsByTagName("input")
i = 0
For Each input In allInputs
If i > l Then Exit For
result(i) = input.value
i = i + 1
Next
.Quit
Exit Do
End If
If .document.body.all.ching.value = "caofackri" Then
.Quit
Exit Do
End If
If Err.Number <> 0 Then Exit Do
Loop
End With
multiInputBox = result
End Function