您的位置:首页 > Web前端 > JQuery

jQuery初认识

2016-07-17 10:37 507 查看
 <!doctype html>
 <html
lang="en">
 <head>
 <meta
charset="UTF-8">
 <title>jQuery的初认识</title>
 <script
type="text/javascript"
src="../jquery/jquery-2.2.3.js" ></script>
 </head>
 <body>
 <script
type="text/javascript">
 /*
 1、jQuery对象
 jQuery里最重要最核心的就是jQuery对象,它是一个全局对象,可以简写成美元符号“$”, 也就是说jQuery对象和$符号是一个意思。当导入jQuery库后,就可以使用jQuery对象了,jQuery的全部方法都放在了这个jQuery对象中。
 */
  
 //补充:之所以设计2个一模一样的对象,是因为将来页面中不仅经只有jQuery库,也许还有其他第三方库,一般库都会用到$符号,所以避免和其他库有冲突,可以选择性使用jQuery对象。
 console.log(jQuery);
 console.log($);
 console.log(jQuery === $);
 console.log(typeof jQuery);
  
 //从这行代码开始:就要把$和jQuery认为是一个构造函数,我们以后所使用的jQuery对象都是通过这个构造函数创建的。
  
 //这个相当于JS中的window.onload = function () {};
 $(document).ready(function () {
 console.log("酸梅汤");
 });
  
 //也可以简写成
 $(function () {
 console.log("北冰洋");
  
 //$body就是一个jQuery对象了,是通过$() 构造函数创建出来的。
 var $body = $("body"); //等价于 var $body = jQuery("body");
 console.log($body instanceof $);
 console.log($body instanceof jQuery);
  
 //以上代码相当于JS中的
 var body = document.body;
 console.log(body instanceof jQuery);
  
 });
  
 </script>
 </body>
 </html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  jquery