如何在 jQuery 中使用变量?
如何在 jQuery 中使用变量?我使用了 var i,这是代码:
var i=0;
for (i=0;i<=5;i++){
$('.slide:eq(i)').delay(3000).fadeOut(500);
}
谢谢。
How to use variable in jQuery? I used the var i, Here's the code:
var i=0;
for (i=0;i<=5;i++){
$('.slide:eq(i)').delay(3000).fadeOut(500);
}
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
它不起作用,因为它被视为普通字符串。
您需要使用“+”连接。
也可以使用:
这样更清晰。
It doesn't "work" because it's treated like a plain string.
You need to concatenate with '+'.
You can also use:
which is clearer.
试试这个...
原因是当你将字符串用引号引起来时,它只是一个字符串!
如果你想使用 :eq() 而不是 .eq(i) 你需要这样做
Try this instead...
The reason is that when you wrap the string in quotes, it's just a string!
If you want to use :eq() instead of .eq(i) you would need to do
您只需将
i
的值放入 jQuery 选择器中即可。You just need to place the value of
i
into the jQuery selector.为什么将 i 设置为 0 两次?尝试如下所示;
您现在正在做的是将变量 i 作为字符串使用。所以 jquery 会看到我真的和我一样。尝试像上面那样连接它。
Why set i to 0 twice? Try something like below;
What you are doing now is using the variable i as an string. SO jquery will see i really as as i. Try concatenating it like above.
试试这个:
try this :