/* jquery.spinner v1.0 copyright (c) 2014 by:loyaoo taobao:http://isseven.taobao.com */
(function($) {
$.fn.spinner = function (opts) {
var defaults = {value:1, min:1, len:3, max:99}
var options = $.extend(defaults, opts)
var keycodes = {up:38, down:40}
return this.each(function() {
var a = $(''); f(a,0,"decrease","-"); //加
var c = $(''); f(c,0,"increase","+"); //减
var b = $('');f(b,1,"amount");cv(0); //值
$(this).append(a).append(b).append(c);
a.click(function(){cv(-1)});
b.keyup(function(){cv(0)});
c.click(function(){cv(+1)});
b.bind('keyup paste change',function(e){
e.keycode==keycodes.up&&cv(+1);
e.keycode==keycodes.down&&cv(-1);
});
function cv(n){
b.val(b.val().replace(/[^\d]/g,''));
bv=parseint(b.val()||options.min)+n;
bv>=options.min&&bv<=options.max&&b.val(bv);
if(bv<=options.min){b.val(options.min);f(a,2,"disde","decrease");}else{f(a,2,"decrease","disde");}
if(bv>=options.max){b.val(options.max);f(c,2,"disin","increase");}else{f(c,2,"increase","disin");}
}
});
function f(o,t,c,s){
t==0&&o.addclass(c).attr("href","javascript:void(0)").append("").find("i").append(s);
t==1&&o.addclass(c).attr({"value":options.value,"readonly":"readonly","autocomplete":"off","maxlength":options.len});
t==2&&o.addclass(c).removeclass(s);
}
}
})(jquery);