jQuery节点列表-如何迭代 [英] jQuery nodelist -- how to iterate

查看:102
本文介绍了jQuery节点列表-如何迭代的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的意思是我想使用for循环或其他方式手动进行迭代.但是我想出的这段代码似乎无法正常工作.我喜欢将javascript与jquery结合使用,因为jquery并不是我的主要项目.我也不太了解jquery,不过我会说我开始学习.您这次如何遍历jquery中的节点列表,这是我这次对所有这些jquery爱好者的问题.它类似于javascript的方式吗?无论如何,这就是我想出的(初学者的代码).

i mean i wanna iterate manually using a for-loop or something. but this piece of code i came up with seems to be not working. i like combining javascript with jquery since jquery is not my cup of tea for major projects. i don't know much jquery either, i would say I'm beginning to learn, though. how do you iterate over a nodelist in jquery is the question i have for all those jquery fans this time. is it similar to the javascript way? anyway this is what i have come up with (the code of a beginner).

$("sn"[i]).fadeIn();

$("sn"[i])根据Google chrome失败的部分.

$("sn"[i]) the part which failed, according to google chrome.

推荐答案

在这种情况下,我认为您的意思是"sn"是节点的选择器:

I think you mean that "sn" is the selector for the nodes, in that case:

$("sn").fadeIn();

这适用于所有与选择器匹配的元素,jQuery将进行迭代.但是,如果要选择所有具有'sn'类的元素,则应在选择器前面加上.,如下所示:".sn"

This works on all the elements that match the selector, jQuery will do the iteration. However if you want to select all elements that have the 'sn' class you should prefix the selector with a . like so: ".sn"

如果要手动循环,请尝试:

if you want to loop manually try:

$(".sn").each(function(i) {
  $(this) // do some magic with the individual element here
});

在此处查看有关每个迭代的更多信息: https://api.jquery.com/each/

See more on iterating with each here: https://api.jquery.com/each/

这篇关于jQuery节点列表-如何迭代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆