在jQuery中联系表单7调用提交事件 [英] Contact form 7 call submit event in jQuery

查看:94
本文介绍了在jQuery中联系表单7调用提交事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的联系表单,最后我添加了一个自定义字段:

 < input type =text name =testid =testclass =form-control> 

我需要检查字段是否为空,然后提交表单:


$ b'$

  $('。wpcf7-submit')。on('click',function(e){
e.preventDefault();

var testInput = $('input [name =test]')。val();

if(testInput!=''){
//如何在这里提交表单?
}
});

如何操作?

解决方案

首先检查它是否为空,然后是preventDefault。然后它将提交

  $('。wpcf7-submit')。on('click',function(e){ 
var testInput = $('input [name =test]')。val();

if(testInput ===''){
e.preventDefault ();
}
});

编辑:

您应该考虑人们不会按提交进行提交,而是按下输入 - 因此您应该可以这样做:

  $(' ('submit',function(){
....
}

而不是听点击


I have a simple contact form and in the end I added a custom field:

<input type="text" name="test" id="test" class="form-control">

I need to check field is empty and then submit form:

$('.wpcf7-submit').on('click', function (e) {
    e.preventDefault();

    var testInput = $('input[name="test"]').val();

    if (testInput != '') {
        // How to submit form here?
    }
});

How to do it?

解决方案

First check if it's empty, then preventDefault. It will then submit otherwise

$('.wpcf7-submit').on('click', function (e) {
    var testInput = $('input[name="test"]').val();

    if (testInput === '') {
        e.preventDefault();
    }
});

EDIT:

You should also consider that people do not submit by pressing submit, but by pressing enter - therefore you should proably do something like this:

$('#myForm').on('submit', function() {
  ....
}

Instead of listening to the click

这篇关于在jQuery中联系表单7调用提交事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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