开发者

jquery keystroke wait

开发者 https://www.devze.com 2023-01-04 16:33 出处:网络
How can I stop the loop until a 开发者_运维知识库key is pushed? for (i=1;i<10;i++){ $(\'input\').eq(i).css(\'border\',\'1px solid red\')

How can I stop the loop until a 开发者_运维知识库key is pushed?

for (i=1;i<10;i++){
    $('input').eq(i).css('border','1px solid red')
    //Wait a keystroke ??????
}


You cannot "stop the loop". You can, however, wait for a "keypress" event.

var i = 1;
$('body').keypress(function() {
  if (i >= 10) return true;
  $('input').eq(i).css('border', '1px solid red');
  i++;
});

That's just an example; there are other ways you might do it.

0

精彩评论

暂无评论...
验证码 换一张
取 消