即使执行返回值,这个表单也会继续提交,我的代码有什么问题?
function formhash (form, password)
{
var pass1 = document.getElementById("password").value;
var pass2 = document.getElementById("cpassword").value;
var ok = true;
if (password != cpassword) {
//alert("Passwords Do not match");
document.getElementById("password").style.borderColor = "#E34234";
document.getElementById("cpassword").style.borderColor = "#E34234";
ok = false;
return;
}
else
{
$.post('insert_home.php'
{PRIMAID:PRIMAID,EDITCAP:EDITCAP,EDITIMG:EDITIMG,EB_TITLE:EB_TITLE}).done(function(data){
alert ("Book Successfully Updated");
location.reload();
});
var p = document.createElement("input");
form.appendChild(p);
p.name="p";
p.type="hidden";
p.value=hex_sha512(password.value);
password.value="";
form.submit();
}
}发布于 2014-01-24 04:07:12
您正在调用form.submit();,删除它,它将不会提交。
发布于 2014-01-24 04:07:28
您使用了错误的变量名"password“和”cpassword“。您创建了pass1和pass2,因此需要使用它们。
更改为以下内容:
//You were using the WRONG variable names
if (pass1 != pass2) {
//alert("Passwords Do not match");
document.getElementById("password").style.borderColor = "#E34234";
document.getElementById("cpassword").style.borderColor = "#E34234";
ok = false;
return false;
}发布于 2014-01-24 04:09:14
我不知道formhash()在哪里使用。
代码调用的是提交,而不是函数。
https://stackoverflow.com/questions/21318221
复制相似问题