gpt4 book ai didi

javascript - 混合批处理/jscript/hta : read 2 inputs in Jscript and pass them to Batch

转载 作者:行者123 更新时间:2023-11-30 19:50:35 30 4
gpt4 key购买 nike

大家早上好

我目前正在编写一个小的 batch/jscript/hta 程序。

在下面的程序中,我读取了一个文本输入字段,将文本传递给批处理并在那里显示:

<!-- :: Batch section
@echo off
setlocal

for /F "delims=" %%a in ('mshta.exe "%~F0"') do set "result=%%a"
echo End of HTA window, reply: "%result%"
pause
goto :EOF
-->


<HTML>
<HEAD>
<HTA:APPLICATION SCROLL="no" SYSMENU="no" >

<TITLE>HTA Buttons</TITLE>
<SCRIPT language="JavaScript">
window.resizeTo(374,400);

function myFunction() {
var x = document.getElementById("myText").value;
var fso = new ActiveXObject("Scripting.FileSystemObject");
fso.GetStandardStream(1).WriteLine(x);
window.close();
}

</SCRIPT>
</HEAD>
<BODY>
<h3>A demonstration of how to access a Text Field</h3>

<input type="text" id="myText" value="0123">

<p>Click the "Login" button to get the text in the text field.</p>

<button onclick="myFunction()">Login</button>

</BODY>
</HTML>

这很好。

现在我的问题是:如何读取两个文本输入字段并将它们传递给批处理?我总是在 Jscript 部分出错!

在此先感谢,我希望有人能帮助我。

最佳答案

如果您需要返回多个值,最简单的方法是将它们与分隔符连接起来,并正确配置 for/f 以将读取的行拆分为单独的标记

<!-- :: Batch section
@echo off
setlocal enableextensions disabledelayedexpansion

rem Defined which tokens we need and the delimiter between them
for /F "tokens=1,2 delims=|" %%a in ('mshta.exe "%~F0"') do (
set "field1=%%a"
set "field2=%%b"
)

echo End of HTA window, reply: "%field1%" "%field2%"
pause
goto :EOF
-->
<HTML><HEAD><HTA:APPLICATION SCROLL="no" SYSMENU="no" >
<TITLE>HTA Buttons</TITLE>
<SCRIPT language="JavaScript">
window.resizeTo(374,400);

function myFunction() {
new ActiveXObject("Scripting.FileSystemObject")
.GetStandardStream(1)
.WriteLine(
[ // Array of elements to return joined with the delimiter
document.getElementById("myText").value
, document.getElementById("myText2").value
].join('|')
);
window.close();
};
</SCRIPT>
</HEAD>
<BODY>
<h3>A demonstration of how to access a Text Field</h3>
<input type="text" id="myText" value="0123">
<input type="text" id="myText2" value="4567">
<p>Click the "Login" button to get the text in the text field.</p>
<button onclick="myFunction()">Login</button>
</BODY>
</HTML>

关于javascript - 混合批处理/jscript/hta : read 2 inputs in Jscript and pass them to Batch,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54514004/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com