gpt4 book ai didi

javascript 密码输入验证启动模式

转载 作者:行者123 更新时间:2023-12-03 00:24:50 25 4
gpt4 key购买 nike

我正在尝试检查两个(密码)输入字段是否相同。如果没有,模式应该启动。我无法让它发挥作用。有人可以建议我解决方案或告诉我我做错了什么。谢谢。

function checkEmail(theForm) {
if (theForm.EMAIL_1.value != theForm.EMAIL_2.value)
{
$('#myModal').modal('show');
}
}
<form action="modal.php" onsubmit="return checkEmail(this);" id="lop">
<p> Enter Your Email Address:<br>
<input type="TEXT" name="EMAIL_1" size="20" maxlength="20">
<br>
Please Confirm Your Email Address:
<br>
<input type="TEXT" name="EMAIL_2" size="20" maxlength="20">
<br>
<input type="SUBMIT" value="Send Address!"></p>
</form>


<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header alert-danger">
<h5 class="modal-title w-100 text-center" id="exampleModalLongTitle">Error</h5>

</div>
<div class="modal-body">
<p class="text-danger text-center">Password does not match</p>
</div>
<div class="modal-footer justify-content-center">
<button type="button" class="btn btn-secondary" data-
dismiss="modal">Cancel</button>

</div>
</div>
</div>

最佳答案

如果您希望 JavaScript 进行输入检查,则需要停止提交表单。

function checkEmail(e) {
e.preventDefault();
const theForm = e.currentTarget;
if (theForm.EMAIL_1.value != theForm.EMAIL_2.value)
{
$('#myModal').modal('show');
return true;
}
theForm.submit(); // same password
}

然后将事件传递到js函数中:

<form action="modal.php" onsubmit="return checkEmail(event);" id="lop">

关于javascript 密码输入验证启动模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54135873/

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