关于jQuery小认知(后期会补充)

$这个符号在Jquery中并不陌生,什么都会用到它,$表示着jquery。一般用于自我复习( 内容部分摘于他人)

$()可以是$(expresion),即css选择器。

eg:$("div")   表示页面中的所有div元素。

 

1 $(document).ready(function(){      //这个函数的执行,是在页面加载完了之后执行,一些方法放这个函数执行,是因为如果页面没有加载完,就执行操作会出现错误
2 
3      $("button").click(function(){
4          $("div").animate({height:"toggle"}).append("hi");
5      });
6  });

$.fn  也是经常遇见的。它表示什么意思呢 。

我们看他的源代码

1 jQuery.fn = jQuery.prototype = {  
2     constructor: jQuery,  
3     init: function( selector, context, rootjQuery ) {  
4     ............  
5     }  
6 }  
7        

即:jQuery.fn == jQuery.prototype, 即jQuery.fn是 jQuery.prototype别称。

这样的话我们就可以对立面添加一些静态方法了。通常是用来制作插件

 1 $.fn.extend({  
 2     sayHello: function(){  
 3         $(this).click(function(){  
 4             alert("hello jquery!");  
 5         });  
 6     }  
 7 });  
 8   
 9 //html代码  
10 <input type="button" value="sayHello" id="sayHello"/>  
11   
12   
13 //使用我们给jQuery新添的方法  
14 $(function(){  
15     $('#sayHello').sayHello();//这个我们可以弹出hello jquery!  
16 });  

先洗去了 ,有时间在更

 

posted @ 2014-06-27 22:53  我是一个菜菜菜  阅读(129)  评论(0编辑  收藏  举报