2

谁能帮助我如何在 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
4

1 回答 1

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>
于 2013-05-31T22:44:03.567 回答