Javascript 我的验证脚本无法正常工作

Javascript 我的验证脚本无法正常工作,javascript,forms,validation,Javascript,Forms,Validation,我正在尝试验证用户名/密码并显示警报。但是它对我不起作用。您没有看到控制台中有任何错误吗 删除此行末尾的分号: function validate() { var username = document.getElementById("username").value; var password = document.getElementById("password").value; if ( username==null || username=="" &&am

我正在尝试验证用户名/密码并显示警报。但是它对我不起作用。

您没有看到控制台中有任何错误吗

删除此行末尾的分号:

function validate()
{
    var username = document.getElementById("username").value;
    var password = document.getElementById("password").value;
    if ( username==null || username=="" && password==null || password=="");
    {
        alert("Please enter username and password");
        return false;
    }
    else ( username == "james1"  && password == "j1j22j3j" )
    {
       alert ("Login successfully");
       window.location = "http://www.dtrekrun.com/training.html"; // Redirecting to other page.
       return false;
    }
}
否则就不要争论,否则就要争论!替换

if ( username==null || username=="" && password==null || password=="");
if ( username==null || username=="" && password==null || password=="");

用这个

else if ( username == "james1"  && password == "j1j22j3j" )
而不是

if ( username==null || username=="" && password==null || password=="")


希望您获得成功

只要在if(username==null | | username==“”&password==null | | password==“”)之后删除分号即可

else
应为
else if
,并从
if
行末尾删除分号。
if ( username==null || username=="" && password==null || password=="");
else ( username == "james1"  && password == "j1j22j3j" )
else if ( username == "james1"  && password == "j1j22j3j" )