简体   繁体   中英

how can I loop on jquery An array of values?

how can I loop on jquery An array of values?

For example:

I have two arrays divs, with id a[i] and b[i], now I want to write script like this:

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

now, how can I replace "1" with var like int

???

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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