Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/410.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/233.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在JavaScript中,当输入不相同或为空时,如何返回False_Javascript_Php - Fatal编程技术网

在JavaScript中,当输入不相同或为空时,如何返回False

在JavaScript中,当输入不相同或为空时,如何返回False,javascript,php,Javascript,Php,当密码和确认密码不相同或密码为空时,我想显示警报并返回false 这是我尝试的 <div class="card margin-card-password"> <div class="card-header">Change Password</div> <div class="card-body"> <form id="change_password" name="change_password" me

当密码和确认密码不相同或密码为空时,我想显示警报并返回false

这是我尝试的

<div class="card margin-card-password">
    <div class="card-header">Change Password</div>
        <div class="card-body">
        <form id="change_password" name="change_password" method="get" action="action/save.php">
            <div class="col-sm-6">
            <div class="form-group">
            <label for="New Password">New Password</label>
            <input type="password" class="form-control" id="password" name="password" value="">
            </div>
            <div class="form-group">
            <label for="Confirm Password">Confirm Password</label>
            <input type="password" class="form-control" id="confirm_password" value="">
            </div>
            </div>
            <div class="col-sm-10">
            <button type="submit" class="btn btn-primary" id="change_password" name="change_password">Save</button>
            </div>
        </form>
    </div>
</div>
js


由于密码变量已指定为输入值,请将password.includes更改为以下内容:

password.length == 0

请注意,我建议您的警报应读为“不正确的密码”,以便于阅读。

由于您的密码变量已指定为输入值,请更改密码。包括以下内容:

password.length == 0
请注意,我建议您的警报应读为“密码不正确”,以便于阅读。

password.includes 这部分代码检查密码是否包含-空字符串。每个字符串都包含空字符串。您需要检查字符串是否是这样的空字符串-password==

希望这对你有帮助

  $('#change_password').on('click', function(){
       var password = $.trim($("#password").val());
       var confirmpassword = $.trim($("#confirm_password").val());
       if(password != confirmpassword || password == ""){
           alert('The Password is Doesnt Same!');
           return false;
       }
    });
还有这个

$('#change_password').on('click', function(){
    var password = $.trim($("#password").val());
    var confirmpassword = $.trim($("#confirm_password").val());
    if(password != confirmpassword){
        alert('The Password is Doesnt Same!');
        return false;
    }else if(password == ""){
        alert('The Password is empty!');
        return false;
    }
});
顺便说一下,很抱歉英语不好

password.includes 这部分代码检查密码是否包含-空字符串。每个字符串都包含空字符串。您需要检查字符串是否是这样的空字符串-password==

希望这对你有帮助

  $('#change_password').on('click', function(){
       var password = $.trim($("#password").val());
       var confirmpassword = $.trim($("#confirm_password").val());
       if(password != confirmpassword || password == ""){
           alert('The Password is Doesnt Same!');
           return false;
       }
    });
还有这个

$('#change_password').on('click', function(){
    var password = $.trim($("#password").val());
    var confirmpassword = $.trim($("#confirm_password").val());
    if(password != confirmpassword){
        alert('The Password is Doesnt Same!');
        return false;
    }else if(password == ""){
        alert('The Password is empty!');
        return false;
    }
});

p.S.对不起,英语不好

控制台有错误吗?password.includes中可能有多余的空格。这可能会导致问题?每个字符串中都有空字符串,因此.includes没有多大意义。id=confirm\u密码标识符在DOM上必须是唯一的。您不应该修剪密码,空格是有效的密码字符。@Xorifelse ok,已经将其删除。console中有错误吗?password.includes中可能有多余的空格。这可能会导致问题?每个字符串中都有空字符串,因此.includes没有多大意义。id=confirm\u密码标识符在DOM上必须是唯一的。您不应该修剪密码,空格是有效的密码字符。@Xorifelse ok,已经删除它了。@Andreas是的。所以我可以知道更多的地方和为什么它错了。@Andreas是的。因此,我可以了解更多错误的地方和原因。