2010-04-04 35 views
8

编写JavaScript和Ajax时,没有适合此功能的文档。我用api src="http://www.google.com/jsapi"searchControl.execute("abhilashm86");搜索这个词。google.setOnLoadCallback(初始化)函数究竟意味着什么?

这个google.setOnLoadCallback(initialize)如何在内部调用?当用户清除之前的搜索并启动一个新的搜索项时,该功能是否仅用于新的搜索项? google.setOnLoadCallback(initialize)究竟如何得到trigerred?

回答

9

当您的文档(包括Google API)被完全加载时,您的初始化函数将被调用。因此,您应该在您传递的函数中包装使用该API的任何代码:

E.g.

google.setOnLoadCallback(function() 
{ 
    var searcher = new google.search.SearchControl(); 
    // More code that depends on the API. 
}); 
1

The documentation说:

使用google.setOnLoadCallback注册到被调用一次加载该文档,而不是GSearch.setOnLoadCallback指定的处理函数。