Home  >  Article  >  Web Front-end  >  简单实现"回车!=提交"(去除表单的回车即提交)_html/css_WEB-ITnose

简单实现"回车!=提交"(去除表单的回车即提交)_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 12:02:591017browse

--------------------------------------------------------------------------------------------------

实现"回车!=提交"的问题,一般可以从"按钮的type类型" 和 "输入框个数"两处着手。

------------------------------@chenwei -------------------------------

默认情况下,单个输入框,无论按钮的type="submit"还是type="button"类型,回车即提交。

1.当type="submit"时,无论有几个type="text"输入框,回车均表示提交。(submit)

2.当type="button"时,且存在多个输入框,回车不提交。(button)

3.解决单个输入框的回车即提交问题,参考第二点:可以增加一个input="text",隐藏; 然后type类型为button。

 

在实际应用中,input输入框很少只有一个的情况,那么只需记住第二条即可应对。

使用JS事件阻止表单提交 不在本文讨论范围,当然也是可以实现的。

--------------------------------------------------------------------------------------------------

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn