jquery第一期:运行第一个jquery

首先下载js文件,网址jquery.com去下载,可以下载1.10版的


首先打开editplus进行编辑,添加js文件:


编写代码:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="js/jquery-1.10.1.js"></script>
<script type="text/javascript">
   $(document).ready(function()
   {
   alert("hello jquery");
   });
</script>
</head>
<body>

</body>
</html>
<script type="text/javascript" src="js/jquery-1.10.1.js"></script>

首先把通过src属性添加js文件


$(document).ready

当文档完全加载完执行的函数


运行结果:



我们完全可以简化我们的代码,

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="js/jquery-1.10.1.js"></script>
<script type="text/javascript">
   $(function()
   {
   alert("hello jquery");
   });
</script>
</head>
<body>

</body>
</html>

也就是说document.ready是可以省略的。




原文地址:https://www.cnblogs.com/pangblog/p/3331452.html