2011-06-06 124 views
2

大家好我是jQuery的新需要帮助理解代码

这段代码书的jQuery在行动第219页

为什么他用.end()方法

,并感谢:)

(function($){ 
$.fn.setReadOnly = function(readonly) { 
return this.filter('input:text') 
.attr('readOnly',readonly) 
.css('opacity', readonly ? 0.5 : 1.0) 
.end(); 
}; 
})(jQuery); 
+0

http://api.jquery.com/end/ – Giacomo 2011-06-06 09:31:42

回答

3

jQuery函数应该返回this以允许链接。

使用.end()他撤消了.filter('input:text')所以最后他返回了this jQuery对象。

+0

谢谢@ThiefMaster – tito11 2011-06-06 09:53:52