IE7默认表单方法是“GET”。如何判断是用户输入还是默认? [英] IE7 default form method is "GET". How can I tell if it's user-entered or default?

查看:96
本文介绍了IE7默认表单方法是“GET”。如何判断是用户输入还是默认?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果用户创建没有方法属性的表单,似乎大多数浏览器将在提交表单时处理此表单。所以在DOM准备好之后检查表单元素,你可以看到表单元素对象没有方法attr。



然而,显然,IE7在没有方法值的情况下,在所有表单上设置默认方法值GET。我不想争论GET或POST是否是最合理的默认值,我只是希望找到一种方式,使POST成为所有浏览器的默认表单方法。



我的问题是,我不知道用户是否为表单方法输入了GET值,或者IE将该值注册为默认值。如果没有表单的方法属性,很明显,用户没有指定一个,所以我可以安全地将其默认为POST。但是,如果我看到一个表单方法的GET值,我无法确定用户是否指定了这个,或者如果它是黑色的,IE7在解析HTML时设置了GET。


$ b $任何人都有任何想法?

解决方案

IE的行为是正确!(*)到DTD:

 方法(GET | POST)GET  - 用于提交表单的HTTP方法 -  

或在XHTML DTD中:

 方法(get | post)get

这意味着如果方法属性被忽略,默认情况下,表单不仅作为GET提交,而且DOM实际上应该包含一个 Attr code>方法与DTD默认值 GET



(* :好的,IE是在HTML文档中使用XHTML小写的默认值,它应该是大写的,不是很重要,因为属性不区分大小写无论如何嘿!这是IE比其他所有浏览器更标准的标准。这是一个奇迹!)



那么你怎么知道 Attr 节点放在那里,因为DTD属性默认而不是因为它在源头?使用DOM 1级核心指定标志:

  var form = document.getElementById('myform'); 
var attr = form.getAttributeNode('method');
var isomitted = attr === null || !attr.specified;


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.

IE7, however, apparently sets a default method value of "GET" on all forms without a method value. 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.

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. 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. 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.

Anyone have any ideas?

解决方案

IE's behaviour is correct!(*) According to DTD:

method      (GET|POST)     GET       -- HTTP method used to submit the form--

or, in the 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.

(*: 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!)

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? With the DOM Level 1 Core specified flag:

var form= document.getElementById('myform');
var attr= form.getAttributeNode('method');
var isomitted= attr===null || !attr.specified;

这篇关于IE7默认表单方法是“GET”。如何判断是用户输入还是默认?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆