简体   繁体   English

如何提交没有操作的表单或提交按钮

[英]How to submit a form without action or submit button

I was looking at one image web site and was puzzled by the javascript they used. 我正在查看一个图像网站,并对他们使用的javascript感到困惑。 The web site has a image, below that there is a text input field you can input your comments. 该网站有一个图像,下面有一个文本输入字段,您可以输入您的评论。 After you input your comments, you press the enter key to commit the comment. 输入注释后,按enter键提交注释。

The html looks like this: html看起来像这样:

 <form class="-cx-PRIVATE-PostInfo__commentCreator" data-reactid=".0.1.0.0.0.2.2.1">
   <input class="-cx-PRIVATE-PostInfo__commentCreatorInput" placeholder="Add a comment…" type="text" value="" data-reactid=".0.1.0.0.0.2.2.1.0">
 </form>

There is no action in the form and no submit button. 表单中没有操作,也没有提交按钮。 How can they submit the form? 他们如何提交表格?

The form's action attribute will default to the current URL. 表单的action属性将默认为当前URL。

Try filling in some text and hitting enter: 尝试填写一些文字并点击输入:

<form>
    <input type="text" name="lookInTheUrlAfterHittingEnter" />
</form>

As @Traktor53 says, hitting enter whilst focus is on the text input will submit the form. 正如@ Traktor53所说,点击输入同时关注文本输入将提交表格。

Input elements of type text (for a single line of text) have submitted their form if the enter key is pressed while filling them in since the year dot AFAIK. 文本类型的输入元素(对于单行文本)已经提交了表单,如果在年份点AFAIK中填写它们时按下回车键。 I did not find any mention of this in HTML5's documentation for this input type element. 我没有在HTML5的文档中找到关于此输入类型元素的任何提及。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM