本文介绍了按回车/回车时,表单提交两次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I'm using anchors as links, and also I'm binding the enter/return key to submit a form, like this:

我使用锚点作为链接,并且绑定了输入/返回键来提交表单,如下所示: (e.keyCode == 13){
$(this)c $ c> $(form [name!= smsform]) .submit();
});

$(a [title = submit])。click(function(){
$(this).parents(form)。submit();
});

$("form[name!=smsform]").bind("keyup", function(e){if(e.keyCode == 13){$(this).submit();});$("a[title=submit]").click( function(){$(this).parents("form").submit();});

然而,当使用上面的代码点击输入/返回时,表单会提交两次,所以我需要合并两个snippets - 任何人都知道如何去做这件事?

However the form submits twice when clicking enter/return using the code above, I need to merge the two snippets - anyone know how to go about this?

推荐答案

当您点击回车时,表单将自动提交,不需要自己编写代码。如果您想在提交之前向enterkey事件添加一些测试,那么您可以从回调函数返回false以阻止默认的浏览器操作。

A form will submit automatically when you click enter, there is no need to write the code yourself. If you want to add some testing to the enterkey event before you submit, then you can return false from the callback function to prevent the default browser action.

这篇关于按回车/回车时,表单提交两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 22:21