快速技巧:解析jQuery – 文本

快速技巧:解析jQuery – 文本

在最新一集中的“剖析 jquery”中,我們將討論 text() 方法,以及 jQuery 1.4 中您可能還不知道的一項新功能。

高級會員:下載此視頻(必須登錄)

訂閱我們的 YouTube 頁面以觀看所有視頻教程!

text 方法的 jQuery 源代碼

 text: function( text ) { 		if ( jQuery.isFunction(text) ) { 			return this.each(function(i) { 				var self = jQuery(this); 				self.text( text.call(this, i, self.text()) ); 			}); 		}  		if ( typeof text !== "object" && text !== undefined ) { 			return this.empty().append( (this[0] && this[0].ownerDocument || document).createTextNode( text ) ); 		}  		return jQuery.text( this ); 	} 

請記住,只有 1.4 或更高版本的用戶才能將函數傳遞給 text() 方法。但這沒問題;如果您仍在使用 1.3,您真的應該停止使用! ??


“剖析 jQuery”系列中的其他章節

  1. 過濾器
  2. 格列普

? 版權聲明
THE END
喜歡就支持一下吧
點贊8 分享