gpt4 book ai didi

javascript - jquery中的li元素列表

转载 作者:行者123 更新时间:2023-11-28 12:43:52 25 4
gpt4 key购买 nike

我不知道为什么我的代码不起作用。

$("#example").find('LI A').hasClass("sth").each(function(){alert($(this))});

Firebug 说:

$("#example").find('LI A').hasClass("sth").each is not a function

这段代码中的问题是each,因为如果我删除它,它不会给我任何错误。

我需要将“a”元素的创建值传递给数组。

最佳答案

hasClass 函数返回 bool 值而不是 jQuery 对象。因此它没有 each 函数。

你的意思可能是这样的:

$("#example").find('LI A.sth').each(function(){alert($(this))});

或者这个(更好):

$("#example li a.sth").each(function(){alert($(this))});

阅读docs :

.hasClass( className ) Returns: Boolean

Description: Determine whether any of the matched elements are assigned the given class

关于javascript - jquery中的li元素列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10058900/

25 4 0
文章推荐: javascript - 如何计算一类的 div,即一类的容器 div 的子级?
文章推荐: html - 无法对齐 bootstrap html 代码中的 div
文章推荐: css - 无法正确放置
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com