提交没有提交按钮且没有页面刷新的表单? [英] Submit a form without submit button and without page refresh?

查看:78
本文介绍了提交没有提交按钮且没有页面刷新的表单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个无法更改的表单,我只能从jquery处理其提交功能.

I have a form which I cannot change and I have to handle its submit function from jquery only.

该表单仅具有单选按钮.我想在选中单选按钮的情况下提交不带页面刷新的表单.

The form have radio buttons only. I want to submit the form without the page refereshed when a radio button is checked.

这是我尝试过的代码.

$('input[type="radio"]').click(function(){
    if ($(this).is(':checked'))
    {
      $('form#my-form').submit(function(){
        alert('form submitted');
      });
    }
});

它应该警告已提交表单",但不会.

It should alert the "form submitted" but it does not.

我做错了什么吗?

推荐答案

如果要提交没有页面加载的表单,则需要使用ajax.

If you want to submit the form without pageload, then you need to go for ajax.

如果要在提交时发出警报,则需要稍微修改您的代码.

If you want the alert while submitting, you need to modify ur code a bit..

$('input[type="radio"]').click(function(){
    if ($(this).is(':checked'))
    {
      $('form#my-form').submit();
    }
});

$('form#my-form').submit(function(){
        alert('form submitted');
      });

这篇关于提交没有提交按钮且没有页面刷新的表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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