如果您想确保您的程序仅在命令行中运行,您可以使用WScript.StdIn 和WScript.StdOut 对象/属性:
var myString = WScript.StdIn.ReadLine();
WScript.StdOut.WriteLine(myString);
并使用cscript.exe 运行它。但是如果你希望它是一个 GUI 程序,考虑到 JScript 没有像 VBScript 这样的原生 InputBox 函数,这有点困难。然而,正如here 所述,我们可以使用Windows Script Host (WSH)。创建.wsf 文件:
<?xml version="1.0" encoding="ISO-8859-1"?>
<job id="testJScriptInputBox">
<script language="VBScript">
<![CDATA[
Function WSHInputBox(Message, Title, Value)
WSHInputBox = InputBox(Message, Title, Value)
End Function
]]>
</script>
<script language="JScript">
<![CDATA[
var vbOKOnly = 0; // Constants for Popup
var vbInformation = 64;
var title = "InputBox function for JScript";
var prompt = "Enter a string: ";
var WshShell = WScript.CreateObject("WScript.Shell");
var result = WSHInputBox(prompt, title, "New York");
if (result != null)
{ // Cancel wasn't clicked, so get input.
var intDoIt = WshShell.Popup(result,
0,
"Result",
vbOKOnly + vbInformation);
}
else
{ // Cancel button was clicked.
var intDoIt = WshShell.Popup("Sorry, no input",
0,
"Result",
vbOKOnly + vbInformation);
}
]]>
</script>
</job>
并使用cscript.exe 或wscript.exe 运行它。或者,您也可以使用 HTML Application (HTA) 创建更精细的 GUI。