我有这个需要的 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 函数。
1 回答
![?](http://img1.sycdn.imooc.com/545863b500014e4602200220-100-100.jpg)
拉风的咖菲猫
TA贡献1995条经验 获得超2个赞
将您的onclick
事件处理程序更改为:
return validate(event, document.thisForm) && submitForm(document.thisForm);
添加回答
举报
0/150
提交
取消