欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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)文章

最新評論