gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 09:23:40 24 4
gpt4 key购买 nike

密码确认密码不相同或当密码为空。

这是我的尝试。

<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

<script type="text/javascript">
$('#change_password').on('click', function(){
var password = $.trim($("#password").val());
var confirmpassword = $.trim($("#confirm_password").val());
if(password != confirmpassword) || (password.includes ("")){
alert('The Password is Doesnt Same!');
return false;
}
});
</script>

最佳答案

密码.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;
}
});

附言对不起英语不好

关于javascript - 如何在 JavaScript 中输入不相同或为空时返回 False,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50101486/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com