任何人都可以告訴我如何去做這個jQuery插件可鏈接?該插件將文本輸入限制在一個字段中,並在傳入時將剩餘的文本計數返回給第二個參數。謝謝。如何讓這個jQuery插件可鏈接?
(function($) {
$.fn.extend({
limit: function(limit, element) {
var interval;
var self=$(this);
$(this).focus(function(){
interval = window.setInterval(function(){
substring(self, limit, element);
},100)
});
$(this).blur(function(){
clearInterval(interval);
substring(self, limit, element);
});
substring(self, limit, element);
}
});
function substring(self, limit, element) {
var val = $(self).val();
var length = val ? val.length : 0 ;
if(length > limit) {
$(self).val($(self).val().substring(0,limit));
}
var toe = typeof element;
if (toe!='undefined') {
if (toe=='string') {
$(element).html((limit-length<=0)?'0':limit-length);
} else if (toe=='object') {
element.html((limit-length<=0)?'0':limit-length);
}
}
}
})(jQuery);
你的意思是直接在substring(self,limit,element)之後;在極限功能? – regan 2012-01-03 22:28:05