动态添加和删除HTA组件

时间:2013-03-24 07:46:14

标签: hta

有人可以帮我解决如何在HTA中动态删除文本框的问题吗?

此代码动态添加文本框:

Sub AddTextBox
    strHTML = DataArea.InnerHTML strHTML=strHTML&"<tr><td>Source Path</td><td><input type="&Chr(34)& _ "text"&Chr(34)&">"&"</td><td><button type="&Chr(34)&"button"&Chr(34)& _ "onclick="&Chr(34)&"RemoveTextBox"&Chr(34)&">"&"x"&"</button></td></tr>"
    DataArea.InnerHTML = strHTML
    tabHTML = tabHTML & strHTML
End Sub

1 个答案:

答案 0 :(得分:0)

我相信这与您正在寻找的相似,这至少会为您提供一个可以构建的工作示例。 Window_OnLoad子例程加载初始内容,然后新创建的内容包含一个按钮,单击该按钮将删除文本框/按钮并添加标记为Add Again?的新按钮。这个新按钮可以再次调用Window_OnLoad子例程并重新加载原始内容。

<html>
<head>
<title>Dynamically Add Controls</title>
<HTA:APPLICATION
  APPLICATIONNAME="Dynamically Add Controls"
  ID="Dynamically_Add_Controls"
  VERSION="1.0"/>
</head>

<script language="VBScript">

Sub Window_OnLoad
    strHTML = "<tr><td>Source Path</td><td><input type="& Chr(34)& "text"&Chr(34)&">"&"</td><td><button type="&Chr(34)&"button"&Chr(34)& "onclick="&Chr(34)&"RemoveTextBox"&Chr(34)&">"&"Remove All?"&"</button></td></tr>"
    DataArea.InnerHTML = strHTML
End Sub

Sub RemoveTextBox()
    strHTML = "<td><button type="&Chr(34)&"button"&Chr(34)& "onclick="&Chr(34)&"Window_OnLoad"&Chr(34)&">"&"Add Again?"&"</button></td></tr>"
    DataArea.InnerHTML = strHTML
End Sub

</script>

<body bgcolor="white">
    <table border="0" cellspacing="0" cellpadding="0">
        <tr>
            <td valign="top"><Div id="DataArea"></Div></td>
        </tr>
    </table>
</body>
</html>