关于if的嵌套问题
发布于 5 年前 作者 pengwei 1732 次浏览 来自 问答

关于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,

});

}

})

2 回复

来个代码片段耍一下?

.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,

});

}

})

回到顶部