input focus in jquery mobile, but keyboard doesn't appear

后端 未结 5 2202
轻奢々
轻奢々 2020-12-30 22:33

I\'m using jquery,jquery mobile and phonegap. I want to show the keyboard one this page with input type=\"text\".

    
相关标签:
5条回答
  • 2020-12-30 22:40

    i use this in cordova 6 for android mobile app and its works:

    -install cordova plugin keyboard: cordova plugin add cordova-plugin-keyboard

    -then u can use Keyboard.show() to show keyboard and keyboard.hide() to hide it

    • u can do this to show keyboard:

        $("#your_text_input").click(function () {
                      $(this).focus();
                      Keyboard.show();
        });
      
        $('#your_text_input').keydown(function(e) {
        if (e.which == 13) { //Enter keycode
          //your action
          ...
      
          // Now clear input and set focus back to input
          Keyboard.hide();
          $(this).val('').trigger("keyup").focus();
        }
        });
      
    0 讨论(0)
  • 2020-12-30 22:48

    None of the previous solutions worked for me. However, I noticed that $('textarea').focus().select(); worked after I access the page a second time. So, I force the jquery mobile to data-prefetch my comment box page.

    This is my generic JQM initialization code (which doesn't work without 'data-prefetch'):

    $('#comment-box-page').live('pageshow', function () {
       $('textarea').focus().select();
    });
    

    On the list page there is a fake image of a small text box, that redirects to comment-box.html, which is just a big test area with post and cancel buttons.

            <div data-role="footer" data-position="fixed" data-theme="b" data-tap-toggle="false">
            <div data-role="fieldcontain">
                <a href="comment-box.html" data-prefetch><img src="fake-textfield.jpg"/>
                </a>
            </div>
        </div>
    
    • data-prefetch is what is making the difference. When you click the link, the page will behave as it was the second time you visited it, enabling focus and bringing the keyboard up.
    0 讨论(0)
  • 2020-12-30 22:52
    $("input").bind( "blur", function () {
           $(".ui-header-fixed" ).css("top","0 !important");
    });
    
    0 讨论(0)
  • 2020-12-30 23:06

    You have to use the "click" event to open the keyboard:

    $(document).live('click', function() {
        $("#input-element-id").focus();
    });
    
    0 讨论(0)
  • 2020-12-30 23:07

    you can't. the mobile browser don`t show the keyboard if you focus an input element. The user has to tap the input element.

    0 讨论(0)
提交回复
热议问题