gpt4 book ai didi

jquery - 循环遍历具有给定类和名称的 div

转载 作者:行者123 更新时间:2023-12-01 08:24:10 24 4
gpt4 key购买 nike

我的页面中有多个 div:

<div imageId='image5' name='5' class='speechBubble'>
<div imageId='image5' name='5' class='speechBubble'>
<div imageId='image6' name='6' class='speechBubble'>
...

使用 jquery,我想为给定的 userId 循环这些 div。我需要说具有类“speechBubble”且名称为 n (5,6) 的循环 div

谢谢

最佳答案

您可以使用.filter().each()功能:

$('.speechBubble').filter(function() {
return this.name.match(/^[56]{1}$/);
}).each(function(index, element) {
// TODO: do something with the element
// for example get the imageId attribute
var imageId = $(element).attr('imageId');
});

如果您想匹配 userId 变量,则不需要过滤功能。你可以这样做:

$('.speechBubble[name=' + userId + ']').each(function(index, element) {
// TODO: do something with the element
// for example get the imageId attribute
var imageId = $(element).attr('imageId');
});

关于jquery - 循环遍历具有给定类和名称的 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5203454/

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