jQuery:调用preventDefault()后调用action的表单 [英] jQuery: call the action's form after calling preventDefault()

查看:83
本文介绍了jQuery:调用preventDefault()后调用action的表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码显示未填写字段时的错误消息。

The code below shows an error message when a field is not filled.

正如您所见,我正在调用preventDefault(),但是...如何如果字段已被填充,则调用与表单关联的操作??

As you can see I'm calling preventDefault(), but...how to call the action associated to the form if the field has been filled??

$('input#save').click(function(e){
  e.preventDefault()

  if($('#field_1').val() == ''){

    $('#error_file').show();

  }
});


推荐答案

$('input#save').click(function(e){
  e.preventDefault()

  if($('#field_1').val() == ''){

    $('#error_file').show();

  }
  else 
  {
     $('#my_form').submit();
  }
});

这篇关于jQuery:调用preventDefault()后调用action的表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆