点击增加span 的数字加1,点击减少span减1如何做?

增加
弑天下
浏览 619回答 2
2回答

拉风的咖菲猫

想了想还是不要直接绑定事件了,这样的写法一点营养都没有。HTML增加减少增加减少增加减少scriptfunctionComponent(el,options){this.opts=$.extend({initVal:0,maxVal:30},options);this.$el=el;this._currVal=this.opts.initVal;this.$add=this.$el.find('button:first');this.$sub=this.$el.find('button:last');this.$show=this.$el.find('span');this.render(this._currVal);this.$add.on('click',$.proxy(this.handleAdd,this));this.$sub.on('click',$.proxy(this.handleSub,this));}$.extend(Component.prototype,{handleAdd:function(){this.render(this._currVal+1);},handleSub:function(){this.render(this._currVal-1);},render:function(val){if(val=this.opts.maxVal){this._currVal=this.opts.maxVal;}else{this._currVal=val;}this.$show.text(this._currVal);},getCurrVal:function(){returnthis._currVal;}});newComponent($('#example'));newComponent($('#example1'),{initVal:5,maxVal:20});varcomponent=newComponent($('#example2'),{initVal:10,maxVal:30});component.getCurrVal();

狐的传说

varchange=function(num){varspan=document.getElementById('cc'),spanNum=span.innerText*1;spanNum+=num;if(spanNum>30){spanNum=0;}if(spanNum
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript