![](/img/trans.png)
[英]create the object of json and pass data to the server using the VBScipt
[英]How to pass HTA Form data (as months and years) to an external Vbscipt file
我正在創建一個 HTA,從中運行一些外部 VBS 文件。 我需要將一些 forms(單選按鈕)的數據從 HTA 傳遞到 VBS 文件。 我應該在 HTA 文件中添加什么來完成它? 在 VBS 中?
這是我到目前為止創建的代碼:
<head><title>Dashboard_Script</title></head>
<meta http-equiv="x-ua-compatible" content="IE=10">
<Script language="VBScript">Set Wss=CreateObject("WScript.Shell")</script>
<body><table><tr><td align="center">
<br><br> DASHBOARD SCRIPTS<br>
<form name="Form1">
<input type="Button" name="Button1" value="SalesReport ">
<SCRIPT FOR="Button1" EVENT="onClick" LANGUAGE="VBScript">
Wss.Run("C:\SalesReport.vbs")
</SCRIPT>
<table>
<tr>
<p>Please select Month from:</p>
<th><input type="radio" id="age1" name="age1" value="1">
<label for="age1">1</label><br></th>
<th><input type="radio" id="age1" name="age1" value="2">
<label for="age2">2</label><br></th>
.........................................................
.........................................................
</tr>
</table>
</fieldset>
</form>
不要使用表格。 那是為了將數據傳遞到服務器。 您可以獲得所選單選按鈕的值,但由於您必須遍歷單選按鈕以找出選擇了哪個單選按鈕,因此您可以只使用循環計數器作為月份索引。 還可以考慮使用 Select 菜單或一系列按鈕。 下面的代碼顯示了所有三種方法。 在所有情況下,它都會將命令行上的月份索引傳遞給 VBS 腳本。 下面的代碼傳遞了 1-12 的值。 但是,如果接收腳本設置了月份數組,則傳遞從零開始的索引(即 0-11)可能更方便。 這是一個小調整。
當然,可以擴展此代碼以獲得其他參數,例如年份。
請注意,代碼使用 MsgBox 進行調試。 另外,避免使用表格。 當需要讓它變得漂亮時,使用帶有類的 Divs 和 CSS 進行樣式設置。
<!DOCTYPE html>
<html>
<head>
<title>Dashboard_Script</title>
<meta charset="UTF-8" http-equiv="x-ua-compatible" content="IE=9">
<script language="VBScript">
Set oWSH=CreateObject("WScript.Shell")
Sub SalesReport1
For i = 0 To 11
If Age1(i).Checked Then Exit For
Next
If i<12 Then
MsgBox "C:\SalesReport.vbs " & i+1
'oWSH.Run("C:\SalesReport.vbs " & i+1)
End If
End Sub
Sub SalesReport2
If Age2.SelectedIndex<>0 Then
MsgBox "C:\SalesReport.vbs " & Age2.SelectedIndex
'oWSH.Run("C:\SalesReport.vbs " & Age2.SelectedIndex)
End If
End Sub
Sub SalesReport3(i)
MsgBox "C:\SalesReport.vbs " & i
'oWSH.Run("C:\SalesReport.vbs " & i)
End Sub
</script>
</head>
<body>
<h2>Dashboard Scripts</h2>
<input type=button value=SalesReport onclick=SalesReport1()>
Please select Month:<br>
<input type=radio name=Age1>January
<input type=radio name=Age1>February
<input type=radio name=Age1>March
<input type=radio name=Age1>April
<input type=radio name=Age1>May
<input type=radio name=Age1>June
<input type=radio name=Age1>July
<input type=radio name=Age1>August
<input type=radio name=Age1>September
<input type=radio name=Age1>October
<input type=radio name=Age1>November
<input type=radio name=Age1>December
<br><br>
<input type=button value=SalesReport onclick=SalesReport2()>
Please select:
<select id=Age2>
<option selected disabled>Month</option>
<option>January</option>
<option>February</option>
<option>March</option>
<option>April</option>
<option>May</option>
<option>June</option>
<option>July</option>
<option>August</option>
<option>September</option>
<option>October</option>
<option>November</option>
<option>December
</select><br><br>
Click a sales report:<br>
<input type=button value=January onclick=SalesReport3(1)>
<input type=button value=February onclick=SalesReport3(2)>
<input type=button value=March onclick=SalesReport3(3)>
<input type=button value=April onclick=SalesReport3(4)>
<input type=button value=May onclick=SalesReport3(5)>
<input type=button value=June onclick=SalesReport3(6)>
<input type=button value=July onclick=SalesReport3(7)>
<input type=button value=August onclick=SalesReport3(8)>
<input type=button value=September onclick=SalesReport3(9)>
<input type=button value=October onclick=SalesReport3(10)>
<input type=button value=November onclick=SalesReport3(11)>
<input type=button value=December onclick=SalesReport3(12)>
</body>
</html>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.