1 /** 2 * 简单计数 3 * @constructor 4 * @name vui.counter 5 * @author dong<dongdong4@staff.sina.com.cn> 6 */ 7 vui.counter={ 8 /** @lends vui.counter*/ 9 k:[], 10 v:[], 11 12 /** 13 * 获取 14 * @name vui.counter.get 15 * @param {String} name 16 * @return {String} 获取该键对应的值 17 */ 18 get:function(name){ 19 var i=this.k.indexOf(name); 20 if(i<0){ 21 return 0; 22 } 23 return this.v[i]; 24 }, 25 26 /** 27 * 增加 28 * @name vui.counter.inc 29 * @param {String} name 30 * @return {Void} 键加1 31 */ 32 inc:function(name){ 33 var i=this.k.indexOf(name); 34 if(i<0){ 35 this.k.push(name); 36 this.v.push(1); 37 return 1; 38 } 39 else{ 40 this.v[i]++; 41 return this.v[i]; 42 } 43 }, 44 45 /** 46 * 减少 47 * @name vui.counter.dec 48 * @param {String} name 49 * @return {Void} 键减1 50 */ 51 dec:function(name){ 52 var i=this.k.indexOf(name); 53 if(i<0){ 54 return 0; 55 } 56 else{ 57 if(this.v[i]>0){ 58 this.v[i]--; 59 } 60 return this.v[i]; 61 } 62 } 63 }; 64 65