[英]why my form is not being submitted even after the passwords match.?
This is my Piece of script with form id="details" 这是我的脚本,形式为id =“ details”
<script type="text/javascript">
function onLoad() {
$("#password").keyup(passCheck);
$("#repeatpass").keyup(passCheck);
}
function passCheck() {
var password = $("#password").val();
var repeatpass = $("#repeatpass").val();
if (password == repeatpass) {
$("#matchpass").text("Passwords match");
$("#matchpass").addClass("valid");
$("#matchpass").removeClass("error");
$("#details").submit(true);
} else {
$("#matchpass").text("Passwords donot match");
$("#matchpass").addClass("error");
$("#matchpass").removeClass("valid");
$("#details").submit(false);
}
}
$(document).ready(onLoad);
</script>
I want to know why my form(id="details") is not being submitted and if someone can explain how this structure works, it will be more helpful for me. 我想知道为什么不提交我的表单(id =“ details”),并且如果有人可以解释此结构的工作原理,则对我会有所帮助。 thanks
谢谢
Working fiddle . 工作提琴 。
Use $("#details").submit()
instead of $("#details").submit(true);
使用
$("#details").submit()
代替$("#details").submit(true);
and remove $("#details").submit(false);
并删除
$("#details").submit(false);
. 。
Hope this helps. 希望这可以帮助。
For starters you do not need to have a .submit
call in the else block. 对于初学者,您无需在else块中进行
.submit
调用。
This code works in three steps: 此代码分为三个步骤:
(1) The .ready
command tells jQuery that when the page is ready it should execute the function named onLoad
. (1)
.ready
命令告诉jQuery,当页面准备就绪时,应执行名为onLoad
的函数。
(2) The onLoad
function tells that when a key from the keyboard is pressed then the passCheck
function should be called. (2)
onLoad
函数告诉您,当按下键盘上的某个键时,应该调用passCheck
函数。
(3) The passCheck
function checks to see if the two texts are equal and if so submits the form, otherwise it does not submit (ie The .submit should not be called at all). (3)
passCheck
函数检查两个文本是否相等,如果相等,则提交表单,否则不提交(即,根本不应该调用.submit)。
Probably the two passwords are both empty initially so they are equal and the .submit
is attempted but an error on that prevents the function a ms the script stops working. 最初两个密码可能都是空的,所以它们是相等的,并且尝试了
.submit
,但是由于出现错误而导致脚本停止工作的错误。 After that the script stops working completely. 之后,脚本将完全停止工作。
Both notes on the request for the HTML code and the note on the argument given to the .submit
, mentioned above are correct. 上面提到的有关HTML代码请求的注释和提供给
.submit
的参数的.submit
都是正确的。
You should not pass parameter in your submit
function remove your $("#details").submit(true);
您不应在
submit
函数中传递参数,请删除$("#details").submit(true);
and $("#details").submit(false);
和
$("#details").submit(false);
its not there in jquery API write this fragment of code it will be of better use: 它不在jquery API中编写此代码片段,将更好地使用:
$( "form" ).submit(function(event) {
if ( $( "span" ).hasClass('error')) {
alert('prevented');
event.preventDefault();
}
return;
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.