我正在尝试完成一些事情,然后再提交表单。以下代码运行无误,但我的表单从未提交过。我不知道怎么了..

<form method="post" id="weber-form" class="af-form-wrapper" action="http://www.aweber.com/scripts/addlead.pl">
    <input class="textInputaweb" type="text" name="email" id="email" size="20" value='Enter Email'  onfocus=" if (this.value == 'Enter Email' ) { this.value = ''; }" onblur="if (this.value == '') { this.value='Enter Email';} " />
    <input id="submit" name="submit" class="submitaweber" type="submit" value="Submit"  />
</form>

<script>
    $(function() {
        $('#submit').click(function (e) {
            e.preventDefault();
            // Do something...
            $('#weber-form').submit();
        });
    }
</script>

最佳答案

为了使以下脚本起作用,请使用the submit button must NOT have a name or id with the value "submit"。像这样的按钮将起作用:

<input class="submitaweber" type="submit" value="Submit"  />

演示:http://jsfiddle.net/MYht8/
$(function() {

    //we bind to the form instead of the form button
    //using .on() (jQ1.7+)
    $('#weber-form').on('submit', function(e) {

        //prevent form submission
        e.preventDefault();

        //do stuff

        //use the native submit so we wont trigger
        //this handler again
        this.submit();
    });
});​

10-06 15:51
查看更多