我有一个表单,我在提交时执行 javascript 验证功能:
<form method="post" onsubmit="return validateForm(this.id)" action="<?php echo $PHP_SELF; ?>" enctype="multipart/form-data" id='addjournalinfoform' style='border:0px;width:90%' class="formular" >
<fieldset>
<legend>
Journal
</legend>
<label>
<span>* ISSN:</span><br />
<input type='text' onfocusout="validateField('issn')" class='text-input' value="" name="issn" id="issn" style='width:30%'>
</label>
</fieldset>
</form>
这是功能:
function validateForm(form)
{
if(form=="addjournalinfoform")
{
alert('onSubmit');
if($('#issn').val()=="")
{
$('#issnMsg').hide(500);
$('#issnMsg .formErrorContent').html("* This field is required!<br />");
$('#issnMsg').css('margin-left', $('#'+field).width()-20);
$('#issnMsg').show(500);
$('#issn').focus();
$('html:not(:animated),body:not(:animated)').animate({scrollTop: $('#issn').offset().top-50}, 0);
return false;
}
else
{
return true;
}
}
return false;
}
问题是即使函数返回 false,表单仍然被提交。做错了什么?以及如何防止提交?