gpt4 book ai didi

javascript - 如何获取所有具有固定起始字符串的html元素

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

我有很多带有 id 的 html 元素 喜欢

        "demo1"
"demo2"
"demo3"

还有更多

        "demoNth"

如何使用 jquery 获取所有元素?

最佳答案

您可以使用以下内容:

这将获取所有以 demo 开头的元素

$("[id^=demo]")

Selector documentation here

使用 each() -> 遍历它们

$("[id^=demo]").each(function(index) {
alert(index + ': ' + $(this).text());
});

each documentation here

关于javascript - 如何获取所有具有固定起始字符串的html元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8573814/

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