jquery
html中使用外部的js文件
<head> <script src="filename.js"></script> </head>
引入jquery的方法有两种首先可以自己下载包,共有两个版本的 jQuery 可供下载:一份是精简过的,另一份是未压缩的(供调试或阅读)。这两个版本都可从 jQuery.com 下载
第二种方法是:
库的替代
Google 和 Microsoft 对 jQuery 的支持都很好。
如果您不愿意在自己的计算机上存放 jQuery 库,那么可以从 Google 或 Microsoft 加载 CDN jQuery 核心文件。
使用 Google 的 CDN
<head> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs /jquery/1.4.0/jquery.min.js"></script> </head>
使用 Microsoft 的 CDN
weiruanjq.html如下
<head> <script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery /jquery-1.4.min.js"></script> </head>
注意:其中<script>的type属性可选,h5中省略,因为javascript是浏览器默认地脚本语言,
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>jquery学习网</title> <script src="//ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.3.min.js"></script> <script src="jqueryjs.js"></script> <script> $(document).ready(function(){ $("button").click(function(){ $("p").hide(1000); }); $("#show").click(function(){ $("p").show(1000); }); }); </script> </head> <body> <p>这是一个段落。</p> <p>这是另一个段落。</p> <button id="hide" type="button">隐藏</button> <button id="show" type="button">显示</button> <p>演示带有不同参数的 fadeToggle() 方法。</p> <button>点击这里,使三个矩形淡入淡出</button> <br><br> <div id="div1" style="width:80px;height:80px;background-color:red;"></div> <br> <div id="div2" style="width:80px;height:80px;background-color:green;"></div> <br> <div id="div3" style="width:80px;height:80px;background-color:blue;"></div> </body> </html>
jqueryjs.js如下:
$(document).ready(function(){ $("button").click(function(){ $("#div1").fadeToggle(); $("#div2").fadeToggle("slow"); $("#div3").fadeToggle(3000); }); });