what javascript will simulate selection from the google maps api 3 places autocomplete dropdown?

落花浮王杯 提交于 2019-12-07 10:23:25

问题


I'm trying to automate the selection of items (using jQuery) from the autocomplete dropdown of the google maps api v3 places library. I am unable to determine the javascript required to select the item from the dropdown.

So, for example, here are the steps required to complete a partial field and trigger the dropdown for something like google's demo of this resource:

[EDIT the following code updated to show solution...]

$('input[name=address]').val("525 Bergen Street");
$('input[name=address]').trigger("focus");
$('input[name=address]').simulate("keydown", { keyCode: $.ui.keyCode.DOWN });
$('input[name=address]').simulate("keydown", { keyCode: $.ui.keyCode.ENTER });

[EDIT...see Engineer's reference to simulate, below.]

Any suggestions would be greatly appreciated, thanks,

Lille


回答1:


Try to use jquery.simulate.js :

$(elem).simulate(mouse_or_keyboard_event_type, options);

Supported event types:

  • mouse: mouseover, mouseout, mousedown, mouseup, mousemove, click, dblclick
  • keyboard: keyup, keydown, keypress


来源:https://stackoverflow.com/questions/10062725/what-javascript-will-simulate-selection-from-the-google-maps-api-3-places-autoco

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