gpt4 book ai didi

jquery - 为什么我不能手动提交此表单?

转载 作者:太空狗 更新时间:2023-10-29 15:27:31 24 4
gpt4 key购买 nike

我想在提交表单之前完成一些事情。以下代码运行无误,但我的表单从未提交过。我说不出哪里出了问题..

<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();
});
});​

关于jquery - 为什么我不能手动提交此表单?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9765695/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com