關於jQuery小認知(後期會補充)

來源:互聯網
上載者:User

標籤:style   blog   java   color   使用   cti   

$這個符號在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 });  

先洗去了 ,有時間在更

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.