Google Ajax Library API使用方法(JQuery)

Google Ajax Library API使用方法

1.传统方式:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>

2.使用google.load载入:

<script src="http://www.google.com/jsapi?key=INSERT-YOUR-KEY" type="text/javascript"></script>
<script type="text/javascript">
google.load("jquery","1");//Load jQuery(1代表1.9+的最新版本,也可具体指定1.8.2)
(function(){
//根据传入的url,在head里生成script引用DOM对象
function createScriptLink(url){
var scriptElement = document.createElement('script');
    scriptElement.setAttribute('type', 'text/javascript');
        scriptElement.setAttribute('src', url);
document.head.appendChild(scriptElement);
}
window.jQuery || createScriptLink('//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js')
if (typeof jQuery == 'undefined') createScriptLink('//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js');
})();
</script>
<script src="http://www.google.com/jsapi?key=INSERT-YOUR-KEY"></script>
<script>
    google.load("jquery", "1");//Load jQuery
    google.load("swfobject", "2.2");
    google.load('maps', '2', {'callback': googleMapSetup });
    google.setOnLoadCallback(function() {
        $(function() {
          // Place init code here instead of $(document).ready()
        });
    });

//页面输出script引用 if (typeof jQuery == 'undefined')
document.write(unescape("%3Cscript src='js/jquery.1.7.1.min.js' type='text/javascript'%3E%3C/script%3E")); window.jQuery || document.write('<script src="js/jquery.1.7.1.min.js" type="text/javascript"></script>') </script>
posted @ 2014-04-11 18:09  Mr.Leo  阅读(700)  评论(0编辑  收藏  举报