HJG.228
2021-09-26 02:00
采纳率: 100%
浏览 47
已结题

有没有老哥能帮我看一下为什么else内的东西不生效呀?

function abc(){
var number1,number2,sum,sum1,sum2,label2,label1,tc;
label1 = document.getElementById("label1").textContent;
label2 = document.getElementById("label2").textContent;
number1 = document.getElementById("textbox1").value;
number2 = document.getElementById("textbox2").value;
number1 = Number(number1);
number2 = Number(number2);
sum1 = number1 * label1;
sum2 = number2 * label2;
sum = Number(sum1) + Number(sum2);
sum = Number(sum);
if (number1>100|| number<0 || number2>100 || number<0) {
alert(sum);
} else {
alert("888");
}

    }function abc(){
        var number1,number2,sum,sum1,sum2,label2,label1,tc;
        label1 = document.getElementById("label1").textContent;
        label2 = document.getElementById("label2").textContent;
        number1 = document.getElementById("textbox1").value;
        number2 = document.getElementById("textbox2").value; 
        number1 = Number(number1);
        number2 = Number(number2);
        sum1 = number1 * label1;
        sum2 = number2 * label2;
        sum = Number(sum1) + Number(sum2);
        sum = Number(sum);
        if (number1>100|| number<0 || number2>100 || number<0) {
        alert(sum);
        } else {
        alert("888");
        } 
        
        
    }
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

  • 最佳回答

    你只定义了| number1 number2
    没有定义 number

    if (number1 > 100 || number < 0 || number2 > 100 || number < 0) {
    

    应该改成

     if (number1 > 100 || number1 < 0 || number2 > 100 || number2 < 0) {
    
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题