【问题标题】:jquery focus on mobile safari does not workjquery专注于移动Safari不起作用
【发布时间】:2015-12-06 18:11:28
【问题描述】:

在用户输入一个数字后,我想关注下一个输入字段。这是我的输入:

<input type="text" pattern="\d*" name="id1" maxlength="1" id="1">
<input type="text" pattern="\d*" name="id2" maxlength="1" id="2">
<input type="text" pattern="\d*" name="id3" maxlength="1" id="3">
<input type="text" pattern="\d*" name="id4" maxlength="1" id="4">

这是我的 jQuery:

$(document).ready(function(){
      $('.in').keyup(function(){
        var i = parseInt($(this).attr('id'));
        if(i != 4){
            i = i + 1;
            s = 'id';
            s +=  i;
            $('input[name='+s+']').focus();
        }else{
            $('.confirm').show();
        }
      });
    });

在 Firefox、IE 等上一切正常。只有在 Mobile Safari 上,焦点不起作用。我必须在下一个输入字段中点击以“重新激活”用于输入值的数字块。

有什么想法吗?

您好,谢谢, yab86

【问题讨论】:

  • 据我所知,Mobile Safari 仅支持关注触摸事件。

标签: jquery html jquery-mobile


【解决方案1】:

Focus() 适用于 iOS。也许尝试使用双引号

$('input[name="'+s+'"]').focus();

或更改 keyup 的选择器

$('input').keyup(function(){

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-27
    • 2012-04-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多