我有这个需要的 html 代码:
//html code
<a href="javascript:void(0);" title="Save" onclick="validate(event, document.thisForm); return submitForm(document.thisForm);"></a>
<form name="thisForm">
//some stuff without submit button and required inputs
</form
我的 JS 看起来像这样:
function validate(event, form)
{
var error = '';
var $inputs = jQuery(form).find(':input[required]');
$inputs.each( function() {
if(jQuery(this).val().length === 0) {
error += 'missing value';
return;
}
});
if (error !== '') {
event.preventDefault();
event.stopPropagation();
event.stopImmediatePropagation();
window.alert(error);
return false;
}
return true;
}
问题在于,当验证出现问题时,它不可能停止调用 submitForm 函数。
拉风的咖菲猫
相关分类