html 表单中的条目“action='?'”是什么意思?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17781842/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What does an entry "action='?'" in html form mean?
提问by user2605845
I have found an entry in html file
我在 html 文件中找到了一个条目
'<form action="?" ... '
I do not understand what it does. Search in Google returned no results. Actually it is a Django template file, but I didn't find anything in django template documentation.
我不明白它的作用。在 Google 中搜索未返回任何结果。实际上它是一个 Django 模板文件,但我在 django 模板文档中没有找到任何内容。
回答by Ignacio Vazquez-Abrams
It uses the current URL with an empty query string as the action of the form. An emptyquery string. Empty. Meaning no query string at all. The query string will be no more. It will not be used. It will be gone. There will be no more query string after submitting the form. The query string will have vanished. Disappeared. Gone away. Become no more.
它使用带有空查询字符串的当前 URL 作为表单的操作。一个空的查询字符串。空的。意味着根本没有查询字符串。查询字符串将不再存在。它不会被使用。它会消失的。提交表单后将不再有查询字符串。查询字符串将消失。消失了。走了。变得不再。
回答by AnaMaria
The action= atrribute has only value. i.e URL. In simple english once your form is processed and you hit a submit button or enter you will be redirected to the URL you give to the action attribute
action= 属性只有值。即网址。用简单的英语,一旦您的表单被处理并点击提交按钮或输入,您将被重定向到您提供给 action 属性的 URL
Example:
例子:
<form action="demo_form.asp" method="get">
First name: <input type="text" name="fname"><br>
Last name: <input type="text" name="lname"><br>
<input type="submit" value="Submit">
</form>
In the case of you question, if the action is "?" then the returned hash-string will be current URL plus "/?" appended which will take you back to the same page you were on.
在你的问题的情况下,如果动作是“?” 那么返回的哈希字符串将是当前 URL 加上“/?” 附加,它将带您返回到您所在的同一页面。
action="" will resolve to the page's address. action="?" will resolve to the page's address + ?, which will mean an empty fragment identifier.
action="" 将解析为页面地址。动作=“?” 将解析为页面地址 + ?,这意味着一个空的片段标识符。
Doing the latter might prevent a navigation (new load) to the same page and instead try to jump to the element with the id in the fragment identifier. But, since it's empty, it won't jump anywhere.
执行后者可能会阻止导航(新加载)到同一页面,而是尝试跳转到片段标识符中具有 id 的元素。但是,因为它是空的,所以它不会跳到任何地方。
Usually, authors just put # in href-like attributes when they're not going to use the attribute where they're using scripting instead. In these cases, they could just use action="" (or omit it if validation allows).
通常,当作者不打算在使用脚本的地方使用属性时,他们只是将 # 放在类似 href 的属性中。在这些情况下,他们可以只使用 action=""(或者如果验证允许则省略它)。
回答by NivF007
'<form action="?" ... '
strips the query string off of the URL when submitting the form, and submits the form to the current document address (i.e. itself).
'<form action="?" ... '
提交表单时从 URL 中剥离查询字符串,并将表单提交到当前文档地址(即它本身)。
Here is what that means:
这是什么意思:
Let's use the following URL as example:
让我们以以下 URL 为例:
ExampleSite.com**?SearchTerm1=chocolate&SearchTerm2=cake**
ExampleSite.com**?SearchTerm1=chocolate&SearchTerm2=cake**
This URL contains the query string '?SearchTerm1=chocolate&SearchTerm2=cake' and sends that query string to the web site server, attached to the URL.
此 URL 包含查询字符串 ' ?SearchTerm1=chocolate&SearchTerm2=cake' 并将该查询字符串发送到网站服务器,附加到该 URL。
Sometimes, you want to ensure that the URL being passed to the server is stripped of any query strings (i.e. the query is string is removed completely) and only the URL is passed.
有时,您希望确保传递给服务器的 URL 没有任何查询字符串(即完全删除查询字符串)并且只传递 URL。
Let's say you bookmarked the page, using the full URL and query string ExampleSite.com?SearchTerm1=chocolate&SearchTerm2=cake****
假设您使用完整 URL 和查询字符串ExampleSite.com?SearchTerm1=chocolate&SearchTerm2=cake****为页面添加了书签
Now you get to that page, and there is a search form.
现在您到达该页面,并且有一个搜索表单。
You decide to use the search form to search for something new...
您决定使用搜索表单来搜索新内容...
'<form action="?" ... '
, as used above, removes the query string from the URL when the form is submitted, and submits the form to the same page that it came from (usually a 'controller' (a page with programming that determines what to do with the information sent to it by the user) ).
'<form action="?" ... '
,如上所用,在提交表单时从 URL 中删除查询字符串,并将表单提交到它来自的同一页面(通常是一个“控制器”(一个带有编程的页面,用于确定如何处理发送的信息)由用户))。
回答by ShivarajRH
When we don't know the url to go by submit the form we can specify like this, It will reload the same page by appending question mark(?) to url.
当我们通过提交表单不知道要走的 url 时,我们可以像这样指定,它会通过在 url 后附加问号(?)来重新加载同一页面。
I.e, Form is submitted for same page itself. It identifies form is reloaded.
即,表单是为同一页面本身提交的。它标识表单被重新加载。
Note: We can leave action property blank, even though it will work!
注意:我们可以将 action 属性留空,即使它会起作用!
回答by topfun
<form name="test" action="process.php" method="get">
<input type="submit" value="Submit">
The action used here will take you to the process.php
page after clicking the submit button.
In short the action=
is used to go to the specified page(mentioned in the action=
) after filling the form and submitting.
process.php
单击提交按钮后,此处使用的操作将带您进入页面。简而言之,action=
用于action=
在填写表单并提交后转到指定页面(在 中提到的)。
回答by bakslash
action is an attribute used in forms to specify the URL of the file that will process the input control when form is submitted
action 是表单中使用的属性,用于指定提交表单时将处理输入控件的文件的 URL