我希望用户能够单击提交,但如果没有填写正确的字段,则不会通过,并且会出现错误.这可能吗?我知道如何做错误部分,但阻塞提交部分很烦人.
处理表单上的提交事件:
$(document).ready(function() {
$("#yourFormIdHere").submit(function(e) {
// process fields
if (thereWereErrors) {
e.preventDefault();
}
});
});
Run Code Online (Sandbox Code Playgroud)
如果在事件处理程序中调用该event.preventDefault()方法,则会停止发生该事件的默认操作,在提交事件的情况下,默认情况下当然是提交表单...
| 归档时间: |
|
| 查看次数: |
245 次 |
| 最近记录: |