Javascript 未捕获类型错误:$(…)[index]。隐藏/显示不是函数

Javascript 未捕获类型错误:$(…)[index]。隐藏/显示不是函数,javascript,jquery,html,search,children,Javascript,Jquery,Html,Search,Children,我正在为我的站点创建jQuery搜索脚本,但出现以下错误: Uncaught TypeError: $(...)[index].hide is not a function (search.js:9) Uncaught TypeError: $(...)[index].show is not a function (search.js:7) 我知道是什么引起的,但我不知道为什么。我有一个包含多个tr元素的表,每个元素都包含我要搜索的“mod”的名称。以下是我的搜索脚本(search.js):

我正在为我的站点创建jQuery搜索脚本,但出现以下错误:

Uncaught TypeError: $(...)[index].hide is not a function (search.js:9)
Uncaught TypeError: $(...)[index].show is not a function (search.js:7)
我知道是什么引起的,但我不知道为什么。我有一个包含多个tr元素的表,每个元素都包含我要搜索的“mod”的名称。以下是我的搜索脚本(search.js):

这是我要搜索的表:

<table class="table table-hover table-versions-hover modlist">
    <thead>
        <tr>
            <th>
                Mod Name
            </th>
            <th>
                Author(s)
            </th>
        </tr>
    </thead>
    <tbody>
        <tr class="mod">
            <th>
                <a href="Mod%20Link" target="_blank">Mod Name</a>
                <p>
                    This is the description of the mod. This can include any
                    information on what it does or how it works. This
                    description can only be 2 lines long, nothing over, not
                    even a little bit.
                </p>
                <span data-toggle="tooltip" data-placement="top" title=
                "Tooltip on top" class=
                "label label-default">Universal</span>
            </th>
            <th>
                Author(s)
            </th>
        </tr>
        <tr class="mod">
            <th>
                <a href="Mod%20Link" target="_blank">Mod Name #2</a>
                <p>
                    This is the description of the mod. This can include any
                    information on what it does or how it works. This
                    description can only be 2 lines long, nothing over, not
                    even a little bit.
                </p>
                <span data-toggle="tooltip" data-placement="top" title=
                    "Tooltip on top" class=
                    "label label-default">Universal</span>
            </th>
            <th>
                Author(s)
            </th>
        </tr>
    </tbody>
</table>

模组名称
作者

这是对mod的描述。这可以包括任何
有关其功能或工作方式的信息。这
描述只能是2行,没有结束,没有结束
哪怕是一点点。

普遍的 作者 这是对mod的描述。这可以包括任何 有关其功能或工作方式的信息。这 描述只能是2行,没有结束,没有结束 哪怕是一点点。

普遍的 作者
$(“.mod”)
创建一个jQuery对象,其中包含对与
“.mod”选择器匹配的任何DOM元素的引用。jQuery对象是一个类似于数组的对象,其方法类似于
.hide()
.show()
,可以对“数组”中的任何DOM元素执行操作

但是
$(“.mod”)[index]
获取对实际DOM元素的引用,并且DOM元素没有
.hide()
.show()
方法。这就是为什么会出现错误
$(…)[index]。hide不是一个函数

要仅对特定索引处的元素调用
.hide()
.show()
(或其他jQuery方法),可以使用,这将创建另一个jQuery对象,该对象仅包含指定索引处的元素。因为结果仍然是一个jQuery对象,所以可以对其使用类似于
.show()
的方法:

$(".mod").eq(index).show();

@谢谢!解决了,我会把它标记为已解决。编辑:我不能,它需要回答。好的,我把我的评论扩展成了一个回答。另一种选择是使用
$('.mod')。每个(…)
并使用
this
引用回调中的当前元素。
$(".mod").eq(index).show();