js弹窗验证失败

之前这样打代码是有,没有输入用户名是有弹窗出来提示的,现在没有。
<script>

function s(){    var a = document.getElementById('name1').value;    var b = document.getElementById('pw1').value;   
 var c = document.getElementById('pw2').value;    if (a== ""||a== "null") {
        alert("请好好输入用户名!");        return false;
    }    else if (b== ""||b== "null") {
        alert("请正确填写密码!");        return false;
    }    else if (c!=b || c== "null") {
        alert("请输入与上面一样的密码");        return false;
    }    else{        return true;
    }

}
</script>

放在了head标签里面,因为是初学,很多不是很明白,在这先谢过帮我的人。


陪伴而非守候
浏览 648回答 1
1回答

沧海一幻觉

<!DOCTYPE html><html>&nbsp; &nbsp; <head>&nbsp; &nbsp; &nbsp; &nbsp; <meta charset="utf-8" />&nbsp; &nbsp; &nbsp; &nbsp; <title>debug</title>&nbsp; &nbsp; &nbsp; &nbsp; <script>&nbsp; &nbsp; &nbsp; &nbsp; function s(){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var a = document.getElementById('name1').value;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var b = document.getElementById('pw1').value;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var c = document.getElementById('pw2').value;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (a == ""|| a == "null") {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; alert("请好好输入用户名!");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return false;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else if (b == ""|| b == "null") {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; alert("请正确填写密码!");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return false;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else if (c != b || c == "null") {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; alert("请输入与上面一样的密码");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return false;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else{&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return true;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</script>&nbsp; &nbsp; </head>&nbsp; &nbsp; <body>&nbsp; &nbsp; 用户名:<input id="name1" type="text" value="" /><br />&nbsp; &nbsp; 输入密码:<input id="pw1" type="password" value="" />&nbsp; &nbsp; <br />&nbsp; &nbsp; 再次输入密码:<input id="pw2" type="password" value="" /><br />&nbsp; &nbsp; <input onclick="s()" type="button" value="确定" />&nbsp; &nbsp; <!--代码方面是可以执行的 是不是 你 html 方面 哪里 弄错了 --></body></html>
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript