Javascript可以';我不能同时工作

Javascript可以';我不能同时工作,javascript,Javascript,如果我把 if(x != cur_p) and if(new_p != con_p) 在 if(x != cur_p){} if(x!=cur_p)的响应结果将显示,而后者不会显示 反之亦然 如何显示这两个ifs的结果 (假设满足这些条件)问题是在第一个条件之后返回false,因此永远不会到达第二个条件。相反,在每个中设置一个布尔变量,并返回布尔变量(如果两个都不失败,则返回true,如果其中一个失败,则返回false) 首先,您的代码中有一个输入错误 // Boolean va

如果我把

if(x != cur_p)
and 
if(new_p != con_p)

if(x != cur_p){} 
if(x!=cur_p)的响应结果将显示,而后者不会显示

反之亦然

如何显示这两个ifs的结果
(假设满足这些条件)

问题是在第一个条件之后返回
false
,因此永远不会到达第二个条件。相反,在每个中设置一个布尔变量,并返回布尔变量(如果两个都不失败,则返回
true
,如果其中一个失败,则返回
false


首先,您的代码中有一个输入错误

    // Boolean variable starts true, will get set to false if either condition is met:
    var okFlag = true;
    if(x != cur_p)
    {   document.getElementById('msg_cur').innerHTML = ' Your password was incorrect';
        // Set to false
        okFlag = false;
    }   

    if(new_p != con_p)
    {   document.getElementById('msg_p').innerHTML = 'Passwords do not match';
        // Set to false
        okFlag = false;
    }
    // Return the flag, which is either true or false.
    return okFlag;


+1.为了理解这个问题!“HTM”中缺少的“L”不是我猜的原因。但是你的第二个解决方案很好。非常感谢@epascarello你救了我一天
if(x != cur_p){} 
if(new_p != con_p){}
    // Boolean variable starts true, will get set to false if either condition is met:
    var okFlag = true;
    if(x != cur_p)
    {   document.getElementById('msg_cur').innerHTML = ' Your password was incorrect';
        // Set to false
        okFlag = false;
    }   

    if(new_p != con_p)
    {   document.getElementById('msg_p').innerHTML = 'Passwords do not match';
        // Set to false
        okFlag = false;
    }
    // Return the flag, which is either true or false.
    return okFlag;
document.getElementById('msg_p').innerHTM = '';  <-- Missing an L
    if(x != cur_p)
    {   document.getElementById('msg_cur').innerHTML = ' Your password was incorrect';
        return false;
    }   

    if(new_p != con_p)
    {   document.getElementById('msg_p').innerHTML = 'Passwords do not match';
        return false;
    }

    return (true);
    var isValid = true;
    if(x != cur_p)
    {   document.getElementById('msg_cur').innerHTML = ' Your password was incorrect';
        isValid = false;
    }   

    if(new_p != con_p)
    {   document.getElementById('msg_p').innerHTML = 'Passwords do not match';
        isValid = false;
    }

    return isValid;