我不确定这个问题背后的概念是什么,可能是闭包或其他。我不知道为什么这个函数不能执行。在我看来它执行但我的浏览器只是变成空白。不知道发生了什么。
google.maps.event.addListener(map,'click', function searchComplete() {
function outside() {
google.load('search', '1');
var newsSearch;
function onLoad() {
// Create a News Search instance.
newsSearch = new google.search.NewsSearch();
// Set searchComplete as the callback function when a search is
// complete. The newsSearch object will have results in it.
newsSearch.setSearchCompleteCallback(this, searchComplete, null);
// Specify search quer(ies)
newsSearch.execute('Obama');
// Include the required Google branding
google.search.Search.getBranding('branding');
}
// Set a callback to call your code when the page loads
google.setOnLoadCallback(onLoad);
}
outside();
});
我还设置了一个 JSFIDDLE: