form 元素内的字段 name 不要跟 form 属性名称一致
长话短说,看这个 form 元素:
<form method="post" action="_some_action_uri_" id="_form_id_">
<input type="hidden" name="method" value="1" />
</form>
试想一下,使用 document.getElementById('_form_id_').getAttribute('method') 会出现什么情况。Firefox 3, Safari 3, Opera 9.5 都会得到预期 “post”, 但是IE 6 和 7 就没有那么幸运了,得到的是一个 object: 其实就是 <input type="hidden" name="method" value="1" /> 这个元素。
因此,为避免混淆和挽救IE,最好是,as the title.

October 8th, 2008 at 22:37
请问在ff3 safari3 opera9.5里面 需要获得form里面的method
规范的方法是怎么做的
我之前是document.getElementById(’_form_id_’).method
还有其它的么 不要用遍历所有子元素的
October 8th, 2008 at 22:49
@netwjx 正如其名,
getAttribute是用来获取属性值的,直接使用form.method或form['method']方法取的是表单里的字段对象。但是由于浏览器也能够通过form.method或form['method']取得元素的属性值,因此造成混乱。初步怀疑在 IE 里它是不区分这两种方法的,才导致它出现本文中的问题。October 9th, 2008 at 08:42
一直没注意,下次的注意。
October 9th, 2008 at 13:11
ie的form有个elements集合
October 9th, 2008 at 15:06
小细节应该关心,很不错。
@netwjx 其他浏览器也同样支持elements。
October 9th, 2008 at 16:21
又是ie的不规范。
October 9th, 2008 at 20:41
id也是一样,呵呵
另外getAttribute方法默认还不区分大小写
November 7th, 2008 at 18:43
IE的getAttribute方法支持第二个参数,可以设定区分大小写的。
November 7th, 2008 at 18:44
我的留言怎么没发出来?是不是贴的链接太多,当我spam了啊??
November 7th, 2008 at 19:00
没办法,看我的blog吧:http://hax.javaeye.com/blog/264164
November 12th, 2008 at 11:49
John Resig在最新的文章中也提到了这个问题:
http://ejohn.org/blog/deadly-expandos/