[英]Javascript function not getting called at the onclick event of a button
[英]Push Data to JavaScript Function Called with onClick Event
我有一個在事件上調用的JavaScript函數。 看起來像這樣:
function showArrays(event) {
// Taken from Google Maps API Documentation
// Since this polygon has only one path, we can call getPath() to return the
// MVCArray of LatLngs.
var vertices = this.getPath();
var contentString = 'A';
// Replace the info window's content and position.
infoWindow.setContent(contentString);
infoWindow.setPosition(event.latLng);
infoWindow.open(map);
}
我從同一文件中的先前JavaScript函數調用此函數。 我用以下代碼稱呼它:
function initMap(){
var myString = 'abc';
region.addListener('click', showArrays);
infoWindow = new google.maps.InfoWindow;
}
我還想將“ myString”傳遞給showArrays,以便將“ contentString”設置為其值。 但是,我不確定如何在函數之間推送數據。 我嘗試編輯showArrays以同時使用事件參數和數據參數,但這不起作用,可能是因為我的語法錯誤。 有什么想法可以做到嗎? 也許使用JQuery?
function showArrays(event,_str) {
// Taken from Google Maps API Documentation
// Since this polygon has only one path, we can call getPath() to return the
// MVCArray of LatLngs.
var vertices = this.getPath();
var contentString = 'A';
// Replace the info window's content and position.
infoWindow.setContent(contentString+_str);
infoWindow.setPosition(event.latLng);
infoWindow.open(map);
}
function initMap(){
var myString = 'abc';
region.addListener('click', function(event){
showArrays(event, 'myString' )
});
infoWindow = new google.maps.InfoWindow;
}
像這樣調用回調函數,回調函數將觸發帶對象的showArrays
region.addListener('click', function(event){
showArrays(event, 'myString' )
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.