2014-12-07 44 views
1

我一直在尋找如何通過Javascript觸發Android鍵盤。關於輸入焦點的Phonegap Android顯示鍵盤Javascript

我發現了一些答案,但他們都沒有工作。

一種解決方案是在這裏: Showing Android's soft keyboard when a field is .focus()'d using javascript

在上面的例子中有一個按鈕參與,我沒有,但我需要它?

我通過touch-layer.js使用'tap'和'swipe'事件,這似乎禁用了點擊事件以支持點擊。 (https://github.com/cubiq/touch-layer

下面是我嘗試過的代碼,警報觸發器和焦點發生,但鍵盤不顯示。

gt("#txtEmail").on("tap", function() { 
    alert('tap'); 
    $(this)[0].el[0].focus(); 
    $("#txtEmail").trigger('click'); 
}); 

謝謝。

編輯1:第二次嘗試不起作用,即使這似乎更符合該示例。

gt("#txtEmail").on("tap", function() { 
    alert('trigger'); 
    $("#txtEmail").trigger('click'); 
}); 

$("#txtEmail").on("click", function() { 
    alert('recieved'); 
    $(this).focus(); 
}); 

回答

3

除了傑克他的suggstion,請查看ionic-plugin-keyboard。這一個更加積極地被維護和使用。

就我而言,我只是將focus事件綁定到手動顯示鍵盤的處理函數。

$(".my-input").on("focus", function(e) { 
    ... 
    cordova.plugins.Keyboard.show(); 
    ... 
}); 
相關問題