【问题标题】:Get value from input text? [duplicate]从输入文本中获取价值? [复制]
【发布时间】:2022-01-05 16:27:27
【问题描述】:

我想编写一个 HTA JScript,它忽略输入文本字段的值,当按下回车按钮时,会执行 callShellApplication(结合 echo 命令的值和输入文本字段的值)。

这是我已经拥有的代码的 sn-p:

<label for="uname">Command: </label>
    <input type="text" style="color:black; id="command" name="name" required size="20"
           pattern="[a-z]{4,8}">
    <button onclick="callShellApplication('cmd /d /c echo/ &[The value of the text field should be entered here]')">Enter</button>

我可以在那里做什么?

更新:我通过从 hta 文件启动一个批处理文件(使用 2 个命令)解决了这个问题。

【问题讨论】:

    标签: html cmd jscript hta


    【解决方案1】:

    您可以使用子进程模块api直接调用shell脚本(节点js后端js)

    例如。

    var exec = require('child_process').exec, child;
    
    child = exec('cat *.js bad_file | wc -l',
        function (error, stdout, stderr) {
            console.log('stdout: ' + stdout);
            console.log('stderr: ' + stderr);
            if (error !== null) {
                 console.log('exec error: ' + error);
            }
        });
     child();
    

    您可以根据需要自定义此代码

    【讨论】:

    • 是的,但是如何从输入文本字段中读取输入内容?
    • var uname = document.getElementById("uname");
    • 好的,谢谢。以及如何将此 var 添加到命令中?
    • 您可以使用.concat() 函数添加例如let text1 = "command"; var uname = document.getElementById("uname") let result = text1.concat(uname)
    • 是的,我明白了,但是我要在这里补充什么:&lt;button onclick="callShellApplication('cmd /d /c echo/ &amp;[The value of the text field should be entered here]')"&gt;Enter&lt;/button&gt; 抱歉,我对这一切都很陌生。
    猜你喜欢
    • 2020-11-14
    • 1970-01-01
    • 2012-02-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多