jQuery中$this和$(this)的區(qū)別介紹(一看就懂)
更新時間:2015年07月06日 09:29:05 投稿:junjie
這篇文章主要介紹了jQuery中$this和$(this)的區(qū)別介紹(一看就懂),本文用簡潔的語言講解了它們之間的區(qū)別,并給出了一個例子來說明,需要的朋友可以參考下
// this其實是一個Html 元素。 // $this 只是個變量名,加$是為說明其是個jquery對象。 // 而$(this)是個轉(zhuǎn)換,將this表示的dom對象轉(zhuǎn)為jquery對象,這樣就可以使用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其實是一個Html 元素。 // $this 只是個變量名,加$是為說明其是個jquery對象。 // 而$(this)是個轉(zhuǎn)換,將this表示的dom對象轉(zhuǎn)為jquery對象,這樣就可以使用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)
相關(guān)文章
google jQuery 引用文件,jQuery 引用地址集合(jquery 1.2.6至jquery1.5.2)
很多網(wǎng)站都是使用這種方式引入,客戶的瀏覽器可能已經(jīng)緩存過了 jquery??梢灾苯诱{(diào)用本地的,速度更快2011-04-04jquery實現(xiàn)全選、反選、獲得所有選中的checkbox
這篇文章主要介紹了jquery實現(xiàn)全選、反選、獲得所有選中的checkbox功能,對checkbox感興趣的小伙伴們可以參考一下2015-12-12jquery創(chuàng)建并行對象或者合并對象的實現(xiàn)代碼
如果有對象A ,B 現(xiàn)在我想要合并成對象C 從C里面可以找到A , B 及其子對象 怎么做2012-10-10分享2個jQuery插件--jquery.fileupload與artdialog
這篇文章主要介紹了分享2個jQuery插件--jquery.fileupload與artdialog的使用方法及示例,非常的實用,這里推薦給大家。2014-12-12