把关注点放在使用Jquery的下一个输入上 [英] Take focus on next input after key up using Jquery

查看:157
本文介绍了把关注点放在使用Jquery的下一个输入上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

注意:我的页面只有文本框。没有其他的。 (没有别的=>没有其他输入类型)

$ $ $input [type ='text'])。 (function(event){

if(valid)
{
//将焦点放在下一个输入元素上,这又是一个文本类型
}

});

如何将焦点移至下一个输入元素。



在Sarfraz之后回答: -

 < div> 
< input type =textmaxlength =1size =1>
< input type =textmaxlength =1size =1>
< input type =textmaxlength =1size =1> // sarfraj - 在这里它崩溃请检查下面的错误。
< / div>


< div>
< input type =textmaxlength =1size =1>
< input type =textmaxlength =1size =1>
< input type =textmaxlength =1size =1>
< / div>

从firebug问题是

 [Break On This Error] $(this).next '[类型= 文本]')[0] .focus(); 


解决方案

更新:



这是你应该如何修改你的代码:

  $(:input [type ='text' ()))。keyup(function(event){
if(valid){
if($(this).next('[type =text]')。length> 0){
$(this).next('[type =text]')[0] .focus();
}
else {
if($(this) ()。next()。find('[type =text]')。length(0){
$(this).parent()。next =text]')[0] .focus();
}
else {
alert('没有更多的文本输入!');
}
}

}
});








使用 next()焦点

  $(this).next(' [类型= 文本]')[0] .focus(); 

所以这里是你的代码应该是这样的:
$ b $如果(有效的){
$($),$ b $ $ $ $这个).next('[type =text]')[0] .focus();
}
});


Note: My page has just textboxes. Nothing else. (nothing else => no other input types)

 $(":input[type='text']").keyup(function(event){

   if(valid)
     {
         // take a focus to next input element, which is again a text type.
     }

  });

How can i jump the focus to next input element after key up.

After Sarfraz Answer:-

 <div>
   <input type="text" maxlength="1" size="1" >
   <input type="text" maxlength="1" size="1" > 
   <input type="text" maxlength="1" size="1" > // sarfraj -- here it crash   Please check below for error.
 </div>


 <div>
   <input type="text" maxlength="1" size="1" >
   <input type="text" maxlength="1" size="1" >
   <input type="text" maxlength="1" size="1" >
 </div>

From firebug issue is

  $(this).next("[type=\"text\"]")[0] is undefined
  [Break On This Error] $(this).next('[type="text"]')[0].focus(); 

解决方案

Update:

Here is how you should modify your code:

$(":input[type='text']").keyup(function(event){
   if(valid) {
      if ($(this).next('[type="text"]').length > 0){
         $(this).next('[type="text"]')[0].focus();
      }
      else{
         if ($(this).parent().next().find('[type="text"]').length > 0){
            $(this).parent().next().find('[type="text"]')[0].focus();
         }
         else {
           alert('no more text input found !');
         }
      }

   }
});


How can i jump the focus to next input element after key up.

Use the next() with focus:

$(this).next('[type="text"]')[0].focus();

So here is how your code should look like:

$(":input[type='text']").keyup(function(event){
   if(valid) {
      $(this).next('[type="text"]')[0].focus();
   }
});

这篇关于把关注点放在使用Jquery的下一个输入上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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