使用GoogleAPI加载各种js框架

时间:2022-04-23
本文章向大家介绍使用GoogleAPI加载各种js框架,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

很多人(包括我)都喜欢把主流的javascript框架(比如jQuery),放到自己服务器上,其实还有更好的选择。

http://code.google.com/intl/zh-CN/apis/ajaxlibs/documentation/index.html#googleDotLoad 是google对外开放的AJAX库 API,上面已经有很多ajax库了,我们只需要引用即可(好处在于:google的服务器还是相当稳定的,而且速度也不错,另外上面的js库全都启用了gzip压缩,体积比较小)

使用步骤:

1.先js引用http://www.google.com/jsapi

2.然后在一段单独的script代码中利用google.load("框架名称","框架版本")来加载

完整示例代码:

<!doctype html>
<html>
	<head>
		<meta http-equiv="content-type" content="text/html; charset=gb3212">
		<title>javascript测试</title>
		<script type="text/javascript" src="http://www.google.com/jsapi"></script>
		<script type="text/javascript">
			google.load("jquery","1.3.1");
		</script>
		<script type="text/javascript">
		$().ready(function(){
			alert("jquery加载成功!");
	})
	</script>
</head>
	<body>	
	</body>
</html>