iOS 8 3rd party keyboards don't register javascript/jQuery keyup, keypress, keydown etc

风流意气都作罢 提交于 2019-12-21 06:51:12

问题


When using a 3rd party keyboard like Swiftkey javascript events like keypress don't register. For example Google maps autocomplete won't work https://developers.google.com/maps/documentation/javascript/examples/places-autocomplete

Seems like an iOS bug but any ideas on how I can get around this?


回答1:


Would this work?

jQuery('#text_box').on('input propertychange paste', function() {
    // text has changed...
});

JSFIDDLE




回答2:


You can just manually fire keypress events.

$textBox = $('#text_box') // We don't want to search the dom more than we have to.
setInterval(function(){
    $textBox.trigger('keypress')
}, 500)

This is definitely a messy solution, but it should get autocomplete to work, as well as other handlers that wait for keypresses.




回答3:


I found a solution using setInterval and the answered method from here Trigger Google Places Autocomplete

setInterval(function() {
if ($('input#mapSearch').is(':focus')) {
google.maps.event.trigger(document.getElementById('mapSearch'), 'focus', {});
}
}, 500);


来源:https://stackoverflow.com/questions/26080368/ios-8-3rd-party-keyboards-dont-register-javascript-jquery-keyup-keypress-keyd

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!