我想使用jQuery提交一个表单。有人能提供代码,演示或示例链接吗?


当前回答

你也可以使用jquery表单插件使用ajax提交:

http://malsup.com/jquery/form/

其他回答

我的方法略有不同,将按钮更改为提交按钮,然后单击

$("#submit").click(function (event) {
  $(this).attr("type", "submit");
  $(this).click();
});

的信息 如果有人使用

$('#formId').submit();

不是这样的吗

<button name = "submit">

我花了很长时间才发现submit()不能像这样工作。

在jQuery我更喜欢以下:

$("#form-id").submit()

但话又说回来,你真的不需要jQuery来执行这个任务-只需使用常规的JavaScript:

document.getElementById("form-id").submit()

这将发送一个带有预加载器的表单:

var a=$('#yourform').serialize();
$.ajax({
    type:'post',
    url:'receiver url',
    data:a,
    beforeSend:function(){
        launchpreloader();
    },
    complete:function(){
        stopPreloader();
    },
    success:function(result){
         alert(result);
    }
});

我有一些技巧,使一个表单数据post随机方法改革http://www.jackart4.com/article.html

使用它来提交你的表单使用jquery。 这里是http://api.jquery.com/submit/的链接

<form id="form" method="post" action="#">
    <input type="text" id="input">
    <input type="button" id="button" value="Submit">
</form>

<script type="text/javascript">
$(document).ready(function () {
    $( "#button" ).click(function() {
        $( "#form" ).submit();
    });
});
</script>