形式没有行动,并输入不重新加载页面 [英] form with no action and where enter does not reload page

查看:112
本文介绍了形式没有行动,并输入不重新加载页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找最新的方式来创建一个没有提交按钮的HTML表单。这本身就很简单,但我还需要在完成提交时停止重新加载表单(例如,在文本字段中敲击 Enter )。

$ b $ (通过普通的js或jquery $()。submit(fn))添加一个onsubmit处理函数,并且返回false,除非你的特定条件是除非你不希望表单提交,否则 - 在这种情况下,为什么不在表单元素中省略'action'属性? / p>

I am looking for the neatest way to create an HTML form which does not have a submit button. That itself is easy enough, but I also need to stop the form from reloading itself when submission-like things are done (for example, hitting Enter in a text field).

解决方案

Add an onsubmit handler to the form (either via plain js or jquery $().submit(fn)), and return false unless your specific conditions are met.

Unless you don't want the form to submit, ever - in which case, why not just leave out the 'action' attribute on the form element?

这篇关于形式没有行动,并输入不重新加载页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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