我的验证脚本无法正常运行

时间:2014-12-04 15:45:25

标签: javascript forms validation

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;
    }
}

我尝试验证用户名/密码并显示提醒。但它不适合我。

3 个答案:

答案 0 :(得分:0)

你没有在控制台中看到任何错误吗?

删除此行末尾的分号:

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

否则不要参数,否则就是这样!替换

else ( username == "james1"  && password == "j1j22j3j" )

通过

else if ( username == "james1"  && password == "j1j22j3j" )

答案 1 :(得分:0)

使用此

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

而不是

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

else ( username == "james1"  && password == "j1j22j3j" )

通过

else if ( username == "james1"  && password == "j1j22j3j" )

希望你获得成功

答案 2 :(得分:0)

在if之后删除分号(username == null || username ==“”&& password == null || password ==“”);