Android - html input loses focus when soft keyboard opens (ASP.net)

后端 未结 6 1659
梦谈多话
梦谈多话 2020-12-10 02:05

I\'ve written a web-page login form in ASP.net.

Using a Nexus 4, stock Android 4.2.1, native Chrome browser - when I click on the fields,

6条回答
  •  爱一瞬间的悲伤
    2020-12-10 02:22

    Requires jQuery

    I've been having this problem myself, and ended up using this solution. It might be useful to someone else. In my case, the resizing made it so that the searchbar lost focus.

    // Makes it so that click events are fired on a mobile device.
    $('#searchbar').each(function(){
        this.onclick = function() {}
    });
    
    // Runs an interval 10 times with a 50ms delay. Forces focus.
    $("#searchbar").click(function() {
        var i = 0;
        var interval = window.setInterval(function(){
            if(i > 10) {
                clearInterval(interval);
            }
            $("#searchbar").focus();
            i++;
        }, 50);
    });
    

提交回复
热议问题