在HTA中动态创建按钮会导致onClick

时间:2015-09-01 14:45:32

标签: vbscript onclick hta

我需要一个小的HTA来提供一些列表框和提交按钮,这将启动一些SQL位。当HTML部分是静态的时候一切都很好,但是当我试图使它变为动态时,当前月/年可以默认为下拉代码退出工作并且说我的ButtonClick未定义。 这是代码的简化版本。我尝试过使用btn01_OnClick,ButtonClick()和其他一些毫无结果的变化。思考?

<HEAD>
  <TITLE>Drop Down Menu</TITLE>
  <HTA:APPLICATION ID="oMyApp" 
    APPLICATIONNAME="Drop Down" 
    BORDER="Dialog"
    CAPTION="Yes"
    SCROLL="NO"
    SHOWINTASKBAR="yes"
    SINGLEINSTANCE="yes"
    SYSMENU="Yes"
    WINDOWSTATE="maximize">
</HEAD>

<SCRIPT LANGUAGE="VBScript">

Sub ButtonClick
        Document.write ("Success")
End Sub


Sub Window_OnLoad
strHTML = strHTML & "<BODY><SPAN>"
strHTML = strHTML & "<H2>Select Month</H2>"
strHTML = strHTML & "<P>Select Month: "
strHTML = strHTML & "<SELECT NAME=""Month"">"
    strHTML = strHTML & "<OPTION selected>" & MonthName(Month(Date),False) & "</OPTION>"
    strHTML = strHTML & "<OPTION>January</OPTION>"
strHTML = strHTML & "</SELECT><P>"

strHTML = strHTML & "<P>Select Year: "
strHTML = strHTML & "<SELECT NAME=""Year"">"
    strHTML = strHTML & "<OPTION selected>" & Year(Date) & "</OPTION>"
    strHTML = strHTML & "<OPTION>2014</OPTION>"
strHTML = strHTML & "</SELECT><P>"

strHTML = strHTML & "<BR><BR>"
strHTML = strHTML & "<Input Type = " & Chr(34) & "Button" & Chr(34) & " Name = " & Chr(34) & "btn01" & Chr(34) & " onClick = " & Chr(34) & "ButtonClick" & Chr(34) & " VALUE = " & Chr(34) & "SUBMIT" &  Chr(34) & ">"

strHTML = strHTML & "<BR><BR></SPAN>"
strHTML = strHTML & "</BODY>"
Document.write(strHTML)
    Window.Month.Focus
End Sub

</SCRIPT>

1 个答案:

答案 0 :(得分:1)

您的脚本部分应该是<head>部分的一部分,我会使用

Document.body.innerHtml = strHTML

而不是

Document.write strHTML

示例:

<html>
<head>
  <title>Drop Down Menu</title>
  <HTA:APPLICATION ID="oMyApp"
    ...
    WINDOWSTATE="maximize">

<script language="VBScript">
Sub ButtonClick
  Document.write "Success"
End Sub

Sub Window_OnLoad
  strHTML = "<SPAN>"
  ...
  strHTML = strHTML & "<BR><BR></SPAN>"
  Document.body.innerHtml = strHTML
  Window.Month.Focus
End Sub
</script>
</head>

<body>
</body>
</html>