gpt4 book ai didi

javascript - 未捕获的类型错误 : Object # has no method 'has'

转载 作者:太空宇宙 更新时间:2023-11-03 23:53:24 25 4
gpt4 key购买 nike

我正在尝试使用 jQuery 的 has我的其中一个菜单中的方法来检查当前是否为 <li>有任何 <ul>在里面。如果是,则显示它们,否则隐藏 li .

但是当使用 has 时我收到此错误:

Uncaught TypeError: Object # has no method 'has'

我的代码:

$('nav ul li').click(function () {
console.log(this.has('ul')); //Checking
if ($(this).children('ul').is(":visible")) {
$(this).children('ul').slideUp(250);
} else {
$(this).children('ul').slideDown(250);
}
});

最佳答案

你稍后执行 $(this) 的原因是因为 this 不是 jQuery 对象。您仍然需要执行 $(this).has('ul')

请注意,您还可以使用 $(this).children('ul').slideToggle(250); 来简化切换部分。

关于javascript - 未捕获的类型错误 : Object #<HTMLLIElement> has no method 'has' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19339460/

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