我在问这个,因为我完全丧失了自己,需要一双新鲜的眼睛。Javascript:onSubmit函数在函数完成之前提交表单?
在提交连接的HTML表单时成功调用以下JavaScript函数。该函数启动并运行前两个if
语句(如果它们返回false
,则停止提交)。
然后,第一次测试alert
“之前”出现,然后表单提交,完全错过了功能的其余部分。在测试时,我更改了最后一行返回false
,以便无论发生什么功能,都应返回false
,但表单仍提交。
function validateForm(form)
{
// declare variables linked to the form
var _isbn = auto.isbn.value;
var _idisplay = auto.isbn.title;
var _iref = "1234567890X";
// call empty string function
if (EmptyString(_isbn,_idisplay)==false) return false;
// call check against reference function
if (AgainstRef(_isbn,_iref,_idisplay)==false) return false;
// call check length function
alert("before");///test alert
////// FORM SUBMITS HERE?!? /////////////
if (AutoLength(_isbn)==false) return false;
alert("after");///test alert
// if all conditions have been met allow the form to be submitted
return true;
}
编辑:这是AutoLength
样子:
function AutoLength(_isbn) {
if (_isbn.length == 13) {
return true; {
else {
if (_isbn.length == 10) {
return true; {
else {
alert("You have not entered a valid ISBN10 or ISBN13. Please correct and try again.");
return false;
}
}
你在哪里调用从功能? – greut 2012-01-14 12:32:27
@greut使用 - onSubmit =“return validateAuthor(this) – MadLarkin 2012-01-14 12:35:12
HTML形式的开始标记(