今天的收获还不错,可以自己去发现问题了 ,值得鼓励
今天写了一个代码实现不了,分享一下,望大神解答
var HelloWorldLayer = cc.Layer.extend({ // _mainUI:null, //输入文本1 _inputOneLab:null, //输入文本2 _inputTwoLab:null, //输入文本3 _inputThreeLab:null, //答案输出 _answerOutput:null, //取消按钮 _cancelBtn:null, //确定按钮 _certainBtn:null, ctor:function () { this._super(); this._init(); }, /* *初始化 * */ _init:function() { this._mainUI = ccs.load(res.main_json).node; this.addChild(this._mainUI); this._inputOneLab = this._getWidgetByName(this._mainUI,"TextField_1"); this._inputTwoLab = this._getWidgetByName(this._mainUI,"TextField_4"); this._inputThreeLab = this._getWidgetByName(this._mainUI,"TextField_6"); this._answerOutput = this._getWidgetByName(this._mainUI,"Label_10"); this._cancelBtn = this._getWidgetByName(this._mainUI,"Button_12"); this._certainBtn = this._getWidgetByName(this._mainUI,"Button_14"); this._cancelBtn.addTouchEventListener(this._inputHandler.bind(this),this._mainUI); this._certainBtn.addTouchEventListener(this._inputHandler.bind(this),this._mainUI); }, /* *点击按钮的回调方法 * */ _inputHandler:function(sender,type){ if(type == ccui.Widget.TOUCH_ENDED){ if(sender.name =="Button_12"){ this._checkDeleteAll(); }else if(sender.name =="Button_14"){ this._checkResult(); } } }, /* *取消输出 * */ _checkDeleteAll:function(){ this._inputOneLab.setString(""); this._inputTwoLab.setString(""); this._inputThreeLab.setString(""); this._setLabString("") }, /* *确定输出 * */ _checkResult:function(){ if(this._inputOneLab.getString("") || this._inputTwoLab.getString("") || this._inputThreeLab.getString(""));this._setLabString("请输入三个数字"); var a = parseFloat(this._inputOneLab.getString()); var b = parseFloat(this._inputTwoLab.getString()); var c = parseFloat(this._inputThreeLab.getString()); if(a < b && a < c)this._setLabString(a); else if(a = b && a < c)this._setLabString(a||b); else if(a = c && a < b)this._setLabString(a||c); else if(b < a && b < c)this._setLabString(b); else if(b = a && b < c)this._setLabString(b||a); else if(b = c && b < a)this._setLabString(b||c); else if(c < a && c < b)this._setLabString(c); else if(c = a && c < b)this._setLabString(c||a); else if(c = b && c < a)this._setLabString(c||b); else if(a = b = c)this._setLabString(a||b||c); }, /* *设置文本内容 * */ _setLabString:function(str){ this._answerOutput.setString(str); }, /* *获取文本内容 * */ _getLabString:function(){ return this._answerOutput.getString(); }, /* *获取显示对象 * */ _getWidgetByName : function(par,name){ return ccui.helper.seekWidgetByName(par,name); } }); var HelloWorldScene = cc.Scene.extend({ onEnter:function () { this._super(); var layer = new HelloWorldLayer(); this.addChild(layer); } });