快速技巧:解析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 分享