Using Google Places Search Box. How to initiate a search by clicking a button?

后端 未结 2 1169
小蘑菇
小蘑菇 2021-02-14 17:24

Either I am an idiot or this was an egregious oversight on the part of the Google Maps team.

I am attempting to trigger a places search request on a button click event i

2条回答
  •  一生所求
    2021-02-14 17:52

    You need to first trigger focus on the input element, then trigger a keydown event with code 13 (enter key).

    var input = document.getElementById('target');
    
    google.maps.event.trigger(input, 'focus')
    google.maps.event.trigger(input, 'keydown', {
        keyCode: 13
    });
    

    JSFiddle demo

提交回复
热议问题