javascript函数调用问题
在google maps infowindow对象中,我调用了showHotel()函数,但没有调用它。当我刚刚编写alerert(“”)时,它可以工作,但我自己定义的函数不能工作javascript函数调用问题,javascript,Javascript,在google maps infowindow对象中,我调用了showHotel()函数,但没有调用它。当我刚刚编写alerert(“”)时,它可以工作,但我自己定义的函数不能工作 function showHotel(){ alert('Wapal po'); } var infowindow = new google.maps.InfoWindow({ content: '<a href="#" onclick="showHotel(
function showHotel(){
alert('Wapal po');
}
var infowindow = new google.maps.InfoWindow({
content: '<a href="#" onclick="showHotel()">Show Tasweer</a>'
});
功能展示酒店(){
警报(“Wapal po”);
}
var infowindow=new google.maps.infowindow({
内容:“”
});
您应该在全球范围内申报showHotel
。如果将事件侦听器添加到HTML字符串,则不考虑当前范围。您当前的代码可能如下所示:
window.onload = function(){ //Or any inner function
function showHotel() ... //This declares a local method
...
content: '<a ... onclick="showHotel()">'
...
}
您应该全局声明
showHotel
。如果将事件侦听器添加到HTML字符串,则不考虑当前范围。您当前的代码可能如下所示:
window.onload = function(){ //Or any inner function
function showHotel() ... //This declares a local method
...
content: '<a ... onclick="showHotel()">'
...
}