[英]IE7 default form method is “GET”. How can I tell if it's user-entered or default?
If a user creates a form without a method attribute, it seems like most browsers will handle this at the time of form submission. 如果用户创建没有方法属性的表单,似乎大多数浏览器将在表单提交时处理此问题。 So upon inspection of the form element after the DOM is ready, you can see that there is no "method" attr of the form element object. 因此,在DOM准备好之后检查表单元素时,您可以看到表单元素对象没有“方法”attr。
IE7, however, apparently sets a default method value of "GET" on all forms without a method value. 但是,IE7显然在没有方法值的所有表单上设置了“GET”的默认方法值。 I don't want to argue about whether GET or POST is the most sensible default, I just want to find a way to make POST the default form method across all browsers. 我不想争论GET或POST是否是最合理的默认值,我只是想找到一种方法使POST成为所有浏览器的默认表单方法。
My problem is that I can't tell if the user entered a "GET" value for a form method, or if IE injected that value as default. 我的问题是我无法判断用户是否为表单方法输入了“GET”值,或者IE是否将该值注入默认值。 If there is no method attribute of the form, it is obvious that the users didn't specify one, so I can safely default it to POST. 如果表单没有方法属性,很明显用户没有指定一个,所以我可以安全地将其默认为POST。 But if I see a GET value for a form method, I can't tell if the user specified that, or if it was left black and IE7 set GET when it parsed the HTML. 但是如果我看到一个表单方法的GET值,我无法判断用户是否指定了它,或者它是否为黑色并且IE7在解析HTML时设置了GET。
Anyone have any ideas? 有人有主意吗?
IE's behaviour is correct !(*) According to DTD: IE的行为是正确的 !(*)根据DTD:
method (GET|POST) GET -- HTTP method used to submit the form--
or, in the XHTML DTD: 或者,在XHTML DTD中:
method (get|post) "get"
that means if the method
attribute is omitted, not only does the form submit as GET by default, but the DOM actually should contain an Attr
node for method
with the DTD defaulted value GET
. 这意味着如果省略method
属性,不仅表单默认提交为GET,而且DOM实际上应该包含具有DTD默认值GET
method
的Attr
节点。
(*: well, sort of. IE is using the XHTML lower-case default in an HTML document where it should be the upper-case. Not that it really matters as the attribute is case-insensitive in HTML anyhow. And hey! It's IE getting the standard more-right than all the other browsers. It's a miracle!) (*:好吧,有点.IE正在HTML文档中使用XHTML小写默认值,它应该是大写的。并不是因为HTML无论如何都不区分大小写这个属性真的很重要。嘿!它是IE比其他所有浏览器都更加正确。这是一个奇迹!)
So how do you tell that the Attr
node was put there because of DTD attribute defaulting and not because it was in the source? 那么你怎么知道Attr
节点因为DTD属性默认而被放在那里而不是因为它在源中? With the DOM Level 1 Core specified flag: 使用DOM Level 1 Core 指定标志:
var form= document.getElementById('myform');
var attr= form.getAttributeNode('method');
var isomitted= attr===null || !attr.specified;
This doesn't seem to be in violation of the HTML form spec , which states: 这似乎没有违反HTML表单规范 ,其中规定:
This attribute specifies which HTTP method will be used to submit the form data set. 此属性指定将使用哪种HTTP方法提交表单数据集。 Possible (case-insensitive) values are "get" (the default) and "post". 可能的(不区分大小写)值是“get”(默认值)和“post”。 See the section on form submission for usage information 有关使用信息,请参阅表单提交部分
(How do I reply to a specific reply?) (in reply to bobice:) (我如何回复特定回复?)(回复bobice :)
IE's behaviour is correct! IE的行为是正确的!
If I read the relevant specs correctly, these are all the case in conformant implementations (which IE is not): 如果我正确地阅读了相关规范,那么在符合要求的实现(IE不是这样)中就是这种情况:
form.method == "get" /* IETF and W3C HTMLs and XHTMLs */ || form.method == "GET" /* HTML5* */
form.hasAttribute ("method") == false
form.getAttribute ("method") == ""
form.getAttributeNode ("method") == null
In Chrome "8.0.552.28 beta" on Linux, I get (also not correct) 在Linux上的Chrome“8.0.552.28 beta”中,我得到了(也不正确)
var form = document.createElement ("form")
undefined
form.method == "get" || form.method == "GET"
false /* actual value is "" */
form.hasAttribute ("method") == false
true
form.getAttribute ("method") == ""
false /* actual value is null */
form.getAttributeNode ("method") == null
true
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.