所以这就是我对男孩和女孩的疑惑 - 首先,我是一个完整的菜鸟,因此只是开始所以不要对我太过刻苦。我写了一堆代码来制作.HTA应用程序:
> <html> <head>
>
> <script type="text/vbscript">
>
> Dim objShell Sub Button1_OnClick()
>
> if box2.checked AND box1.checked then
>
> Set objShell = CreateObject( "WScript.Shell" )
> objShell.Run("""%programfiles(x86)%\Mozilla Firefox\firefox.exe""")
> Set objShell = Nothing
>
> Set objShell = CreateObject( "WScript.Shell" ) objShell.Run("cmd.exe")
> Set objShell = Nothing
>
> elseif box1.checked then
>
> Set objShell = CreateObject( "WScript.Shell" ) objShell.Run("cmd.exe")
> Set objShell = Nothing
>
> Elseif box2.checked then
>
> Set objShell = CreateObject( "WScript.Shell" )
> objShell.Run("""%programfiles(x86)%\Mozilla Firefox\firefox.exe""")
> Set objShell = Nothing
>
>
> End If End Sub
>
>
> </script> </head> <body> <font face=Calibri> Check the program you
> would like to run! <br> Available programs to run for now: <br> <input
> type="checkbox" name="box1">CMD <br> <input type="checkbox"
> name="box2">Mozilla <br> <i>Choose which program(s) you'd like to run.
> It is possible to run multiple programs at one time!</i></font><br>
> <input type="button" name="btn1" onclick="Button1_OnClick"
> value="Submit"><br> <div id="error"></div>
>
>
>
> </body> </html>
这完全符合预期,当我检查两个程序时,它们都会运行,当我检查其中一个时,只有一个会运行。但是,如果我在该列表上有50个不同的节目呢?我想有一种更简单的方法来编写这个,而不是为每个程序组合编写if / else / elseif语句的加载?正如上面提到的,我完全不喜欢这个,也许我还没有找到一个更简单的方法......但这也是我问的原因。
答案 0 :(得分:2)
您可以将元素属性用于您的目的。
迭代所有复选框,然后使用存储在自定义属性中的路径启动该过程(如果已选中)。完成点。
<html>
<head>
<script type="text/vbscript">
Dim objShell
Set objShell = CreateObject("WScript.Shell")
Sub StartProcesses
Dim Checkbox
For Each Checkbox In Document.getElementsByName("process")
If Checkbox.Checked Then
objShell.Run """" & Checkbox.getAttribute("path") & """"
End If
Next
End Sub
</script>
</head>
<body>
<font face=Calibri>
Check the program you would like to run! <br>
Available programs to run for now: <br>
<div id="ProcessList">
<input type="checkbox" name="process" path="cmd.exe">CMD <br>
<input type="checkbox" name="process" path="iexplore.exe">Internet Explorer <br>
<input type="checkbox" name="process" path="%programfiles(x86)%\Mozilla Firefox\firefox.exe">Firefox <br>
<input type="checkbox" name="process" path="calc.exe">Calculator <br>
<input type="checkbox" name="process" path="notepad.exe">Notepad <br>
</div>
<i>Choose which program(s) you'd like to run. It is possible to run multiple programs at one time!</i>
</font><br>
<input type="button" onclick="StartProcesses" value="Submit"><br>
<div id="error"></div>
</body>
</html>