简体   繁体   English

Google Map API下拉列表Onchange事件监听器

[英]Google Map API dropdown Onchange event Listener

I've a google map and i want to trigger a function whenever i select value from dynamic drop down . 我有一个谷歌地图,我想在我从动态下拉列表中选择值时触发一个函数。 For that i added a listener and submitted the form like below. 为此,我添加了一个侦听器并提交了如下所示的表单。

var input = document.createElement('input');
input.setAttribute('type', 'text');
input.setAttribute('id', 'pac-input');
input.setAttribute('class', 'controls');
input.setAttribute('placeholder', 'Search By Area');

input.addEventListener("change", function(event) {
    checkInputKey_map(event, $(this));
});

In checkInputKey i'm sending ajax to controller with the selected value , but in post request parameter going is not the full name which was selected . checkInputKey我将使用选定的值将ajax发送到控制器,但是在发布请求参数中,则不是所选的全名。 instead it's the keywords written to get the places . 相反,它是用来获得位置的关键字。 while i want full search names to be sent . 而我想发送完整的搜索名称。 any help will be appreciated 任何帮助将不胜感激

update 更新

function checkInputKey_map(event,this) {
    if ((event.keyCode == 13 || event.type == 'change') && $("#API_source_map").val() == 'yelp_places') {
        searched_place = $('#pac-input').val();
        console.log(searched_place);
    }
}

It feels good but annoying always to post answer to your own question . 发表自己的问题的答案总是很烦人但很烦人。 but all things apart . 但是万物分开。 I made a trick and i applied the same listener to the input but with a delay of one second . 我弄了个花招,将相同的侦听器应用于输入,但延迟了一秒钟。 My final code is like below 我的最终代码如下

var input = document.createElement('input');
input.setAttribute('type','text');
input.setAttribute('id','pac-input');
input.setAttribute('class','controls');
input.setAttribute('placeholder','Search By Area');

input.addEventListener("change", function(event){
setTimeout(function() {
    checkInputKey_map(event, $(this));
},1000);
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM