我想知道是否有人可以给出一个“最佳实践”的回应,使用空白HTML表单动作发布回当前页面。
有一个帖子问一个空白的HTML表单动作在这里做什么,一些像这样的页面认为它是好的,但我想知道人们是怎么想的。
我想知道是否有人可以给出一个“最佳实践”的回应,使用空白HTML表单动作发布回当前页面。
有一个帖子问一个空白的HTML表单动作在这里做什么,一些像这样的页面认为它是好的,但我想知道人们是怎么想的。
当前回答
这将在HTML5中验证。
<form action="#">
其他回答
当我使用Classic ASP时,我经常这样做。我通常在需要对输入进行某种服务器端验证时使用它(在AJAX出现之前)。我所看到的主要缺点是它没有在文件级别上将编程逻辑与表示分开。
只使用
?
<form action="?" method="post" enctype="multipart/form-data" name="myForm" id="myForm">
它并不违反HTML5标准。
当你放空动作时,一些安全过滤认为它是恶意的或网络钓鱼。因此,他们可以阻止你的页面。所以建议不要让action=为空。
在HTML 5中action=""是不支持的,所以不要这样做。不好的实践。
如果你完全否定动作,默认情况下它会提交到同一个页面,我相信这是最好的做法:
<form>This will submit to the current page</form>
如果您使用php提交表单,您可能需要考虑以下内容。点击这里阅读更多信息。
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
或者你也可以使用# bear in mind,这将像一个锚,滚动到页面顶部。
<form action="#">
I use to do not specify action attribute at all. It is actually how my framework is designed all pages get submitted back exact to same address. But today I discovered problem. Sometimes I borrow action attribute value to make some background call (I guess some people name them AJAX). So I found that IE keeps action attribute value as empty if action attribute wasn't specified. It is a bit odd in my understanding, since if no action attribute specified, the JavaScript counterpart has to be at least undefined. Anyway, my point is before you choose best practice you need to understand more context, like will you use the attribute in JavaScript or not.