简体   繁体   English

如何在 jquery 上循环一个值数组?

[英]how can I loop on jquery An array of values?

how can I loop on jquery An array of values?如何在 jquery 上循环一个值数组?

For example:例如:

I have two arrays divs, with id a[i] and b[i], now I want to write script like this:我有两个数组 div,id 为 a[i] 和 b[i],现在我想写这样的脚本:

$("#a\\[1\\]").keyup(function (e) {
   if (e.keyCode === 13) { // enter == 13
       $("#b\\[1\\]").focus();
   }
});

now, how can I replace "1" with var like int现在,我怎样才能用像 int 这样的var替换“1”

??? ???

Do you mean something like this ?你的意思是这样的吗?

 var i = 0; jQuery('a:eq('+i+')').click(function(){ jQuery('b:eq('+i+')').css('color','red'); });
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <a> a1 </a> <a>a2 </a><br/> <b>b1</b> <b>b2</b>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM