2013-03-24 43 views
2

任何人都可以幫助我如何在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 
+0

您想刪除整個'tr'還是'input'? – Teemu 2013-03-26 07:53:49

回答

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>