对于实现这个功能,首先是需要创建3个输入框,还有有个文本框,
需要点击事件,点击回调事件,然后在点击事件里面判断输入的大小。
_init:function(){ this._mainUI =ccs.load(res.main_json).node; this.addChild(this._mainUI); //获取3个输入框 this._inputLab1=this._getWidgetByName(this._mainUI,"TextField_7"); this._inputLab2=this._getWidgetByName(this._mainUI,"TextField_8"); this._inputLab3=this._getWidgetByName(this._mainUI,"TextField_9"); this._mesLab=this._getWidgetByName(this._mainUI,"Label_10"); this._canleBtn=this._getWidgetByName(this._mainUI,"_canleBtn"); this._okBtn=this._getWidgetByName(this._mainUI,"_okBtn"); this._okBtn.addTouchEventListener(this._inputHandler.bind(this),this._mainUI); this._canleBtn.addTouchEventListener(this._inputHandler.bind(this),this._mainUI); }, _inputHandler:function(sender,type){ if(type==ccui.Widget.TOUCH_ENDED){ if(sender.name=="_okBtn"){ this._checkResult(); }else if(sender.name=="_canleBtn"){ this._inputLab1.setString(""); this._inputLab2.setString(""); this._inputLab3.setString(""); this._mesLab.setString(""); } } }, _checkResult:function(){ var a =parseFloat(this._inputLab1.getString()); var b =parseFloat(this._inputLab2.getString()); var c =parseFloat(this._inputLab3.getString()); if(a<b&&a<c)this._mesLab.setString("最小的值为"+a); else if(b<c&&b<a)this._mesLab.setString("最小的值为"+b); else if(c<a&&c<b)this._mesLab.setString("最小的值为"+c);