提交表单前的jquery函数 [英] Jquery function BEFORE form submission

查看:159
本文介绍了提交表单前的jquery函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在单击表单提交按钮时使用Jquery触发一个函数,但该函数需要在表单实际提交之前触发。

I am trying to fire a function using Jquery when the form submit button is clicked, but the function needs to fire BEFORE the form is actually submitted.

我是尝试在提交时将一些div标签属性复制到隐藏文本字段中,然后提交表单。

I am trying to copy some div tag attributes into hidden text fields upon submission, and then submit the form.

我已经设法使用mouseover函数来工作(当提交按钮悬停在上面),但这不适用于使用触摸的移动设备。

I have managed to get this to work using the mouseover function (when the submit button is hovered over) but this will not work on mobile devices using touch.

$("#create-card-process.design #submit").on("mouseover", function () {
    var textStyleCSS = $("#cover-text").attr('style');
    var textbackgroundCSS = $("#cover-text-wrapper").attr('style');
    $("#cover_text_css").val(textStyleCSS);
    $("#cover_text_background_css").val(textbackgroundCSS);
});

我玩过.submit函数,但这些值并没有保存在字段中函数会在表单提交时触发,而不是在之前触发。

I have played around with the .submit function, but the values are not saved within the fields as the function fires when the form is submitted and not before.

非常感谢

Many thanks

推荐答案

您可以使用onsubmit函数。

You can use the onsubmit function.

如果您返回false,表单将不会被提交。请阅读此处

If you return false the form won't get submitted. Read up about it here.

$('#myform').submit(function() {
  // your code here
});

这篇关于提交表单前的jquery函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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