【问题标题】:How do i return two alerts in JS?如何在 JS 中返回两个警报?
【发布时间】:2022-09-30 19:56:44
【问题描述】:

我编写了这段代码来验证密码,我需要向用户显示两个不同的警报。

1. (pw.length < 8) when this condition executed \"Password need minimum 8 characters\"

2. (pw != cpw) \"Passwords does not match\"


<script>
    function validatePassword(){
        
        var pw= document.getElementById(\"txtPassword\").value;
        var cpw= document.getElementById(\"txtCPassword\").value;

        if((pw.length < 8)||(pw != cpw))
            {
                alert(\"please enter the correct password\")
                return false;
                Event.preventDefault();
            }
        return true;
    }
    
</script>

有没有人知道有什么...

  • 您需要显示 2 个警报吗?因为如果 txtPassword 无效,则可以忽略 txtCPassword。

标签: javascript validation if-statement


【解决方案1】:
<script>
        var pw= document.getElementById("txtPassword").value;
        var cpw= document.getElementById("txtCPassword").value;
    function validatePassword(){
        


        if(pw.length < 8)
            {
                alert("Password need minimum 8 characters")
            }
        if(pw != cpw){
                alert("Passwords does not match")
            }

    }
    

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-01-02
    • 1970-01-01
    • 2016-06-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-07
    相关资源
    最近更新 更多