admin管理员组

文章数量:1391955

I want to make the soft keyboard show on

$( document ).ready(function() {
....
});

here's my html code:

<form id="typerForm">
<input id="typer" style="position:relative; left:-100em;"/>
</form>

<div id="myInput" style="border:2px solid #4AA; width:6em; height:1em; font-size:2em"></div>
<div style="height:20em; background-color:#eee">

</div>    

and here's my javascript code:

$('body').click(function() {
    $('#typer').focus();
    $('#typer').select();

});


$('#typerForm').submit(function() {
    //alert("submit");
    setTimeout("$('#typer').focus();", 1000);
    return false;
});

$('#typer').bind('keyup', function(e) {
    var input = $.trim($(this).val());
    // some lines of code..
    $('#myInput').text(input);
    //...
    //$(this).val('').focus(); // clean up
});

or you can look at my code here /

my code works to show the keyboard on mobile web browser when i click on somewhere or click on the input text. And what i want is show keyboard automatically when the page ready or finish loading

I want to make the soft keyboard show on

$( document ).ready(function() {
....
});

here's my html code:

<form id="typerForm">
<input id="typer" style="position:relative; left:-100em;"/>
</form>

<div id="myInput" style="border:2px solid #4AA; width:6em; height:1em; font-size:2em"></div>
<div style="height:20em; background-color:#eee">

</div>    

and here's my javascript code:

$('body').click(function() {
    $('#typer').focus();
    $('#typer').select();

});


$('#typerForm').submit(function() {
    //alert("submit");
    setTimeout("$('#typer').focus();", 1000);
    return false;
});

$('#typer').bind('keyup', function(e) {
    var input = $.trim($(this).val());
    // some lines of code..
    $('#myInput').text(input);
    //...
    //$(this).val('').focus(); // clean up
});

or you can look at my code here http://jsfiddle/7urry794/

my code works to show the keyboard on mobile web browser when i click on somewhere or click on the input text. And what i want is show keyboard automatically when the page ready or finish loading

Share Improve this question edited May 23, 2017 at 14:32 adn asked May 23, 2017 at 7:15 adnadn 4303 gold badges7 silver badges21 bronze badges 1
  • Please provide code in your question. Else as soon as your link is broken, nobody will be able to re-use the help provided to solve your problem – Nuageux Commented May 23, 2017 at 8:52
Add a ment  | 

2 Answers 2

Reset to default 3

you can use below code to open keyboard on iOS or Android There are a couple of ways I know of to get around this:

prompt() opens the keyboard

If you trigger the .focus() from within a .click() event (e.g. from opening your dialog), the keyboard shows up

Hope it might help

You can do this by calling focus() then click() on the input, but only if the script is initiated by user input. All attempts to get this to work from an onload handler with no user interaction FAILED :-( Beware of endless loops if your script is triggered by an onclick() on a containing element. The script below is working for me on Chrome for android 58 and Safari mobile 602.1, when called from an onclick().

function onSomethingOtherThanLoad(event){
    // get the input
    var target = document.getElementsByTagName("input")[0];
    if (event.target != target) {
        target.focus();
        target.click();
    }
}

本文标签: javascriptAuto Show Soft Keyboard on mobile web browserStack Overflow