2012-08-10 61 views
0

標記:Android鍵盤不開放的必然touchstart輸入標籤

<section id="loginform"> 
    <input type="text" id="username" placeholder="Username"/> 
    <input type="password" id="password" placeholder="Password"/> 
    <input type="submit" value="login" id="login"/> 
</section> 

的JavaScript:

$('#loginform #username').bind('touchstart', function(e) { 
    $(this).focus() 
}) 
$('#loginform #password').bind('touchstart', function() { 
    $(this).focus() 
}) 

打開該網站上的Android(4.0),並單擊輸入字段用戶名或密碼,沒有鍵盤彈出...如果我做這樣的代碼:

$('#loginform #username').bind('touchstart', function(e) { 
    alert("android why u no keyboard show!?") 
    $(this).focus() 
}) 

然後鍵盤會彈出... A lerting e.isDefaultPrevented()返回false

的東西可能是錯的任何想法?

感謝

回答

0

試試這個:你可以把這個代碼在document.ready或者一些別的地方太

$('#username').bind('touchstart', function(e) { 
    $(this).focus() 
}) 
$('#password').bind('touchstart', function() { 
    $(this).focus() 
}) 

可能有一些事件冒泡用了怎麼回事。

+0

沒有工作... :(奇怪爲什麼警報()幫助,如果我把有鍵盤彈出... – Johannes 2012-08-10 10:02:15

+0

我想嘗試加入一些時間間隔延遲,這將有助於該像setTimeout的工作功能。查看此鏈接http://www.electrictoolbox.com/using-settimeout-javascript/ – ankur 2012-08-10 10:41:43