表单元素上的action属性可以为空吗? [英] Can the action attribute on a form element be empty?
本文介绍了表单元素上的action属性可以为空吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
从HTML5开始,广泛使用并推荐的action=""
是无效的HTML.
As of HTML5, the widely used and recommended action=""
is invalid HTML.
根据规格:
如果指定了action和formaction内容属性,则必须具有 一个有效的URL值.
The action and formaction content attributes, if specified, must have a value that is a valid URL.
那么将action
属性指向当前页面的正确方法是什么?
So what is the correct way to have the action
attribute point to the current page?
我当前正在使用
action="<php htmlspecialchars($_SERVER["REQUEST_URI"]); ?>"
推荐答案
的确,action=
属性不能为空,因为空字符串不是有效的URL.但是,简单地将其保留,然后让浏览器将其找出来是有效的.
It's true that the action=
attribute may not be empty, as an empty string is not a valid URL. However, it is valid to simply leave it out, and let the browser figure it out.
浏览器将假定当前页面.
The browser will assume the current page.
这篇关于表单元素上的action属性可以为空吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文