gpt4 book ai didi

html - 过滤 HTML 表格

转载 作者:太空宇宙 更新时间:2023-11-04 16:19:11 24 4
gpt4 key购买 nike

我正在尝试使用 VBScript 过滤我网站上的表格。用户将使用搜索词来缩小结果范围。如果某行有一列包含搜索词,则该行不会隐藏。自从我使用它以来已经有一段时间了,我无法让它工作。 “不工作”是指表格中的所有行仍然出现。

<html>

<script language="VBScript">
Sub filterResults()
Dim searchBox
Set searchBox = Document.forms("searchBoxID")

For Each subInstance In document.GetElementsByTagName("tr")
If Not subInstance.OuterHTML.Contains(searchBox.filterTXT.Value) Then
subInstance.style = "display:none"
End If
Next
End Sub
</script>

<form id="searchBoxID"
onsubmit="filterResults(); return false;" language="jscript">

Filter results:
<input name="filterTXT" type="text" size="2">
<input name="Submit" type="Submit" value="Submit">

<table border=1>
<th>Row One</th><th>Row Two</th><th>Row Three</th>
<tr>
<td>Stuff</td><td>Things</td><td>Items</td>
</tr>
<tr>
<td>Possessions</td><td>Objects</td><td>Things</td>
</tr>
</table>

</html>

最佳答案

VBScript 中没有Contains 方法。使用 InStr功能:

For Each subInstance In document.GetElementsByTagName("tr")
If InStr(subInstance.OuterHTML, searchBox.filterTXT.Value) = 0 Then
subInstance.style = "display:none"
End If
Next

关于html - 过滤 HTML 表格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30472049/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com