1 回答

TA貢獻(xiàn)1895條經(jīng)驗(yàn) 獲得超7個(gè)贊
$ 是JQuery對(duì)象,是JQuery 常用的一個(gè)回傳函數(shù),定義為 "選取" 英文是 selector 的縮寫例子︰$.function();就是 選取 JQuery 定義的 function() 執(zhí)行$('input')就是 選取 HTML 當(dāng)中全部的 input 標(biāo)簽$('#abc')就是 選取 HTML 當(dāng)中 ID 名稱為 abc 的物件$.fn.testing = function() {}就是 選取 JQuery 內(nèi)核函數(shù) fn (函數(shù)) 回傳給 testing 這個(gè)名稱、定義為一個(gè)功能 function()
$this 只是個(gè)變量名,加$是為說(shuō)明其是個(gè)jquery對(duì)象
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | // this其實(shí)是一個(gè)Html 元素。 // $this 只是個(gè)變量名,加$是為說(shuō)明其是個(gè)jquery對(duì)象。 // 而$(this)是個(gè)轉(zhuǎn)換,將this表示的dom對(duì)象轉(zhuǎn)為jquery對(duì)象,這樣就可以使用jquery提供的方法操作。 (function($){ $.fn.hilight = function(options){ debug(this); var defaults = { foreground: 'red', background: 'yellow' }; var opts = $.extend({}, $.fn.hilight.defaults, options); return this.each(function() { // this其實(shí)是一個(gè)Html 元素。 // $this 只是個(gè)變量名,加$是為說(shuō)明其是個(gè)jquery對(duì)象。 // 而$(this)是個(gè)轉(zhuǎn)換,將this表示的dom對(duì)象轉(zhuǎn)為jquery對(duì)象,這樣就可以使用jquery提供的方法操作。 $this = $(this); // build element specific options var o = $.meta ? $.extend({}, opts, $this.data()) : opts; // update element styles $this.css({ backgroundColor: o.background, color: o.foreground }); var markup = $this.html(); // call our format function markup = $.fn.hilight.format(markup); $this.html(markup); }); }; // define our format function $.fn.hilight.format = function(txt) { return '<strong>' + txt + '</strong>'; }; // 插件的defaults $.fn.hilight.defaults = { foreground: 'red', background: 'yellow' }; function debug($obj) { if (window.console && window.console.log){ window.console.log('hilight selection count: ' + $obj.size()); } }; })(jQuery) |
- 1 回答
- 0 關(guān)注
- 473 瀏覽
添加回答
舉報(bào)