收藏
回答

关于if的嵌套问题

关于IF函数的嵌套,下列代码中 表颜色的部分 无法触发。我已经核实触发条件没有问题了  但是颜色部分还是不生效,麻烦大神帮看看 谢谢啦

clickButton: function(e){

console.log(e);

var btnValue = e.target.id;

var res = this.data.result;

var newDotSign = this.data.dotSign;

if (btnValue >= "num_0" && btnValue <= "num_9") {

var num = btnValue.split('_')[1];

if(res == "0") {

res = num;

}else{

res = res+num;

}

}else {

if(btnValue == "dot") {

if(!newDotSign){

res = res+'.';

newDotSign = true;

}

}else if(btnValue == "clear") {

res = "0";

console.log(e.target.id);

console.log(res);

newDotSign = false;

}

}

this.setData({

result:res,

dotSign: newDotSign,

});

}

})


最后一次编辑于  2018-12-05  (未经腾讯允许,不得转载)
邀请回答
复制链接收藏投诉关注问题回答

2 个回答

  • 卢霄霄
    卢霄霄
    2018-12-05

    来个代码片段耍一下?

    2018-12-05
    赞同 1
    回复 11
    • 拾忆
      拾忆
      2018-12-05

      居然还在

      2018-12-05
      回复
    • 卢霄霄
      卢霄霄
      2018-12-05回复拾忆

      晚上回家才有空。。这段时间要加班。。上班比较忙

      2018-12-05
      回复
    • 他的、国
      他的、国
      2018-12-05回复卢霄霄

      麻烦大神 看下  卡码半小时了 感觉不应该啊

      2018-12-05
      回复
    • 卢霄霄
      卢霄霄
      2018-12-05回复他的、国

      https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html

      这个片段哦。。就算你贴代码。。那也把 wxml贴了啊

      2018-12-05
      回复
    • 他的、国
      他的、国
      2018-12-05回复卢霄霄

      wxml:

      <view class='screen'>

      <view> {{result}} </view>

      </view>

      <view class="bottom">

      <view class="btnGroup">

      <button id="{{id1}}" bindtap='clickButton' hover-class='shadow' class='btn-item gray'>清除</button>

      <button id="{{id2}}" bindtap='clickButton' hover-class='shadow' class='btn-item gray'>回退</button>

      <button id="{{id3}}" bindtap='clickButton' hover-class='shadow' class='btn-item gray'>

      <icon type='waiting' size='30' color='#999'></icon>

      </button>

      <button id="{{id4}}" bindtap='clickButton' hover-class='shadow' class='btn-item orange'>/</button>

      </view>

      <view class="btnGroup">

      <button id="{{id5}}" bindtap='clickButton' class='btn-item white' hover-class='shadow'>7</button>

      <button id="{{id6}}" bindtap='clickButton' hover-class='shadow' class='btn-item white'>8</button>

      <button id="{{id7}}" bindtap='clickButton' hover-class='shadow' class='btn-item white'>9</button>

      <button id="{{id8}}" bindtap='clickButton' hover-class='shadow' class='btn-item orange'>*</button>

      </view>

      <view class="btnGroup">

      <button id="{{id9}}" bindtap='clickButton' hover-class='shadow' class='btn-item white'>4</button>

      <button id="{{id10}}" bindtap='clickButton' hover-class='shadow' class='btn-item white'>5</button>

      <button id="{{id11}}" bindtap='clickButton' hover-class='shadow' class='btn-item white'>6</button>

      <button id="{{id12}}" bindtap='clickButton' hover-class='shadow' class='btn-item orange'>-</button>

      </view>

      <view class="btnGroup">

      <button id="{{id13}}" bindtap='clickButton' hover-class='shadow' class='btn-item white'>1</button>

      <button id="{{id14}}" bindtap='clickButton' hover-class='shadow' class='btn-item white'>2</button>

      <button id="{{id15}}" bindtap='clickButton' hover-class='shadow' class='btn-item white'>3</button>

      <button id="{{id16}}" bindtap='clickButton' hover-class='shadow' class='btn-item orange'>+</button>

      </view>

      <view class="btnGroup">

      <button id="{{id17}}" bindtap='clickButton' hover-class='shadow' class='btn-item zero white'>0</button>

      <button id="{{id18}}" bindtap='clickButton' hover-class='shadow' class='btn-item white'>.</button>

      <button id="{{id19}}" bindtap='clickButton' hover-class='shadow' class='btn-item orange'>=</button>

      </view>

      </view>


      2018-12-05
      回复
    查看更多(6)
  • 他的、国
    他的、国
    2018-12-05

    .js

    data: {

    result: "0",

    id1: "chear",

    id2: "back",

    id3: "history",

    id4: "div",

    id5: "num_7",

    id6: "num_8",

    id7: "num_9",

    id8: "mul",

    id9: "num_4",

    id10: "num_5",

    id11: "num_6",

    id12: "sub",

    id13: "num_1",

    id14: "num_2",

    id15: "num_3",

    id16: "add",

    id17: "num_0",

    id18: "dot",

    id19: "equals",

    dotSign: false,


    },

    clickButton: function(e){

    console.log(e);

    var btnValue = e.target.id;

    var res = this.data.result;

    var newDotSign = this.data.dotSign;

    if (btnValue >= "num_0" && btnValue <= "num_9") {

    var num = btnValue.split('_')[1];

    if(res == "0") {

    res = num;

    }else{

    res = res+num;

    }

    }else {

    if(btnValue == "dot") {

    if(!newDotSign){

    res = res+'.';

    newDotSign = true;

    }

    }else if(btnValue == "clear") {

    res = "0";

    console.log(e.target.id);

    console.log(res);

    newDotSign = false;

    }

    }

    this.setData({

    result:res,

    dotSign: newDotSign,

    });

    }

    })


    2018-12-05
    赞同
    回复