標籤: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 });
先洗去了 ,有時間在更