gpt4 book ai didi

javascript - 提交按钮不提交

转载 作者:行者123 更新时间:2023-11-30 13:19:03 27 4
gpt4 key购买 nike

我有一个简单的 html 登录表单,在提交之前使用 javascript 对其进行了验证。当我尝试提交未满足验证条件的表单时,我会像往常一样收到验证警报。但是,当遇到它们时,提交按钮变得无响应。

这是表单的 html 代码:

<form action="staff_login_process.php" class="myform" enctype="multipart/form-data" method="post" onsubmit="return validLog()">

<fieldset>

<div id="apply_width">

<div id="field_area">

<h2 class="white">Login</h2>

<label for="username">Username<span>*</span>
</label> <input type="text" name="email" value="" id="username" class="float_right" />

<label for="password">Password<span>*</span>
</label><input type="password" name="password" value="" id="password" class="float_right" />
<a class="red" href="">Forgot Password</a>

</div>

<input type="submit" value="Login" class="button" />

</div>

</fieldset>

</form>

这是负责验证的 Javascript 代码:

function validLog() {

var username = document.getElementById('username');
var password = document.getElementById('password');


if(notEmpty(username, "Please enter username")){
if(notEmpty(password, "Please enter password")){
}
}

return false;

}

function notEmpty(elem, helperMsg){
if(elem.value.length == 0){
alert(helperMsg);
elem.focus(); // set the focus to this input
return false;
}
return true;
}

我不知道该怎么做才能让它发挥作用,也找不到我哪里出错了,所以任何建议都很好。

谢谢

最佳答案

您的 validLog() 函数总是返回 false

改变

if(notEmpty(username, "Please enter username")){
if(notEmpty(password, "Please enter password")) {
return false;
}
}

return true;

关于javascript - 提交按钮不提交,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10951970/

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