私のVBScriptアプリケーションにSubがあります。検索ボタンをクリックするとページ上に表が表示されますが、window.location.reload()
メソッドを使用してページを消去する別のボタンがあります。条件付きで関数を呼び出す
私の問題は、ユーザーが検索ボタンをクリックしてテーブルを作成した後、ユーザーが再度検索ボタンをクリックすると、テーブルに追加のデータが追加されることです。
最初にページをクリアしてから、テーブルを作成する必要があります。 反復があるので、Search(directory)
Sub内で単にwindow.location.reload()
と呼ぶことはできません。
<p>
<input name="Clear" type="button" class = "button" value="Clear" OnClick="window.location.reload()">
<input name="Search" type="button" class = "buttongo aright" value="Search" OnClick="Search">
</p>
私のVBScriptコードは次のとおりです。
Sub Search(directory)
Dim flag
Dim found
Dim nodeinfo(4)
Dim ipath
On Error Resume Next
Set fldr = fso.GetFolder(FolderPath)
Set Fls = fldr.Files
For Each item In Fls
sFSpec = FSO.GetAbsolutePathName(item)
If LCase(FSO.GetExtensionName(item.Name)) = "xml" Then
objMSXML.async = True
'...
'More code here to generate table mytable ...
'...
End If
Next
Set fldrs = fldr.SubFolders
For Each item In fldrs
Search item.path
Next
End Sub
テーブルにデータがある場合には現在、私は、検索ボタンを無効にしています:
If no_of_occurence > 0 Then document.getElementById("search_btn").disabled = True
編集
生成するにはテーブル:
Set mytable = document.createElement("table")
mytable.setAttribute "id", "mytable"
mytable.setAttribute "align", "center"
Set thead = document.createElement("thead")
Set tr = document.createElement("tr")
Set th = document.createElement("th")
th.setAttribute "colSpan","5"
thead.appendChild tr
Set tr2 = document.createElement("tr")
Set th1 = document.createElement("th")
Set th2 = document.createElement("th")
Set th3 = document.createElement("th")
Set th4 = document.createElement("th")
Set th5 = document.createElement("th")
th1.innerText = "ABC"
th2.innerText = "DEF"
th3.innerText = "GHI"
th4.innerText = "JKL"
th5.innerText = "MNO"
tr2.appendChild th1
tr2.appendChild th2
tr2.appendChild th3
tr2.appendChild th4
tr2.appendChild th5
thead.appendChild tr2
mytable.appendChild thead
Set td1 = document.createElement("td")
td1.innerText = nodeinfo(0)
tr3.appendChild td1
結果が返される場合は数値を保持する変数、たとえばno_of_results
があります。その変数に基づいて、ボタンを無効にしています。
はクールなサウンドをクリックし、単一のボタンの2つの機能を呼び出して、このコードを試してみてください。 :-) – user2816085
両方の機能を呼び出す際に問題が発生しました... – user2816085