UPDATE:我找到了第一个问题的答案。其实我用了两种方法。对于“strBoxTitle”变量,我替换了该行:
<b>strBoxTitle</b><p>
有了这个
<b>
<script>document.write( strBoxTitle )</script>
</b><p>
它正确显示了变量的值,而不是它的名称。然而,这对于“strLocalUser”变量不起作用,因为它位于输入标记内。对于那个,我添加了这一行
document.getElementById("userid").value = strLocalUser
到我的窗口 OnLoad 函数,并将输入标记从
<input id='userid' size=20 class='fixed' value=strLocalUser>
to just
<input id='userid' size=20 class='fixed'>
这也有效,用“strLocalUser”的值填充用户输入字段,更不用说防止我需要在输入标签内嵌套脚本标签,这显然是不允许的。
原问题:
我正在尝试编写一个 HTA 文件,该文件从 Vbscript 文件调用以获取用户输入。使用以下命令调用 HTA 文件
objWShell.Run ".\UserInput.hta | " & "Please Enter Your Credentials" & _
" | " & strLoginID,1,True
我在 Stack Overflow 中编写的 HTA 文件“UserInput.hta”是
<!DOCTYPE html>
<html>
<head>
<hta:application
id = oHTA
border = dialog
innerborder = no
caption = yes
sysmenu = no
maximizebutton = no
minimizebutton = no
scroll = no
singleinstance = no
showintaskbar = no
contextmenu = no
selection = yes
/>
<style type='text/css'>
.fixed { font-family:courier new, monospace }
</style>
</head>
<script language="VBScript">
CmdLine = oHTA.commandLine
Params = Split(CmdLine,"|")
strBoxTitle = Params( 1 )
strLocalUser = Params( 2 )
Sub window_OnLoad
Document.Title = strBoxTitle
Window.ResizeTo 400, 200 + 70
Window.MoveTo Window.screen.width / 2 - 200, Window.screen.height / 2 - 200
End Sub
Function SubmitBtn()
Window.Close
End Function
</script>
<body bgcolor=Silver>
<center><form>
<b>strBoxTitle</b><p>
<table>
<tr><td colspan=2 align=left>
Please enter your username and password:<br><br>
</td></tr><tr><td valign=top>
Username:
</td><td>
<input id='userid' size=20 class='fixed' value=strLocalUser>
</td></tr><tr><td valign=top>
Password:
</td><td>
<input type='password' id='passwd' size=20 class='fixed'><p>
</td></tr>
</table>
<p>
<input type='button' value='Submit' id='but0' onclick='SubmitBtn()'>
</form></center>
</body>
</html>
这会正确显示带有两个输入字段的输入框。不幸的是,这就是我所得到的。我的两个问题是:
- 如何让输入框显示 strBoxTitle 和 strLocalUser 变量的值,而不是文本“strBoxTitle”和“strLocalUser”?
- 如何将用户输入的值从输入框用户 ID 和密码传递回调用 Vbscript?
预先感谢所有指导和建议。