Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/399.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用jQuery在焦点上选择文本框不是';t在移动浏览器中工作_Javascript_Jquery_Html - Fatal编程技术网

Javascript 使用jQuery在焦点上选择文本框不是';t在移动浏览器中工作

Javascript 使用jQuery在焦点上选择文本框不是';t在移动浏览器中工作,javascript,jquery,html,Javascript,Jquery,Html,我在一个页面上有四个最大长度为4的文本框。我的目标是,当用户填充第一个文本框时,焦点自动移动到另一个文本框。我编写的方法在所有web浏览器中都能很好地工作,但在移动浏览器中不行 我正在使用的标记: <input tabindex="3" type="text" id="cnumber1" class="inputBx ccNumber" style="width:57px;margin-left: 11px!important" maxlength="4" size="4" autocom

我在一个页面上有四个最大长度为4的文本框。我的目标是,当用户填充第一个文本框时,焦点自动移动到另一个文本框。我编写的方法在所有web浏览器中都能很好地工作,但在移动浏览器中不行

我正在使用的标记:

<input tabindex="3" type="text" id="cnumber1" class="inputBx ccNumber" style="width:57px;margin-left: 11px!important" maxlength="4" size="4" autocomplete="off" />
        <input tabindex="4" type="text" id="cnumber2" class="ccNumber" style="width:57px;"  maxlength="4" size="4" autocomplete="off"/>
        <input tabindex="5" type="text" id="cnumber3" class="ccNumber" style="width:56px;"  maxlength="4" size="4" autocomplete="off"/>
        <input tabindex="6" type="text" id="cnumber4" class="ccNumber" style="width:56px;"  maxlength="4" size="4" autocomplete="off"/>
(function($) {
  $.switchFocus = function($this) {
    $this.unbind('keyup');
    $this.each(function() {
      $(this).keyup(function(){
        var $this = $(this),
        inputVal = $this.val(),
        iLen = inputVal.length,
        $nextEle = $this.next();
        if (iLen == $this.attr("size") && $nextEle.length > 0){
          if($nextEle.val().length === 0)
            $nextEle.focus();
        }
      });
    });
  }
}(jQuery));

我能得到一些关于为什么手机浏览器会出现这种情况的帮助吗

对于某些移动浏览器来说,这一定是一个bug,但是这种方法应该可以解决您的问题,试试看

(function($) {
  $.switchFocus = function($this) {
    $this.unbind('keyup');
    $this.each(function() {
      $(this).keyup(function(){
        var $this = $(this),
        inputVal = $this.val(),
        iLen = inputVal.length,
        $nextEle = $this.next();
        if (iLen == $this.attr("size") && $nextEle.length > 0){
          if($nextEle.val().length === 0)
            $nextEle.focus();
            setTimeout(function(){$nextEle.focus()},0);
        }
      });
    });
  }
}(jQuery));

对于某些移动浏览器来说,这一定是一个bug,但是这种方法应该可以解决您的问题,试试看

(function($) {
  $.switchFocus = function($this) {
    $this.unbind('keyup');
    $this.each(function() {
      $(this).keyup(function(){
        var $this = $(this),
        inputVal = $this.val(),
        iLen = inputVal.length,
        $nextEle = $this.next();
        if (iLen == $this.attr("size") && $nextEle.length > 0){
          if($nextEle.val().length === 0)
            $nextEle.focus();
            setTimeout(function(){$nextEle.focus()},0);
        }
      });
    });
  }
}(jQuery));

您在尝试哪些移动浏览器?@Ocanal我在iOS模拟器中使用safari。您在尝试哪些移动浏览器?@Ocanal我在iOS模拟器中使用safari。