0

我一直在玩 Android 的 Kik 网络应用程序。我注意到某些事件在用户与页面交互之前不会正确触发。

这个问题在 Kik 中表现出来,但它也出现在我运行 Android 4.4/KitKat 的 Galaxy S5 上的股票网络浏览器中。

HTML

<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>  
click here: <button id="button">a button</button>
<br><br><br>
textbox: <input type="text" id="textbox">

CSS

* {
    font-size: 20px;
}

JavaScript

window.onload=function(e) {
    // set function to button.click
    $('#button').click(function() {
        fucus();
    });

    // run the exact same function rightey-right now
    $('#textbox').focus();

    // run it again in three minutes
    $('#textbox').focus()
};


function fucus() {
    $('#textbox').focus();
}
4

1 回答 1

1

大多数移动浏览器不允许.focus()按预期运行,除非从用户交互事件中调用。例如,如果您在某个onclick事件中调用它,它会起作用,但如果调用onload它则不会。这不是 Kik 特有的,而是一般的移动浏览器。

于 2014-11-09T05:46:01.233 回答