网络编程
位置:首页>> 网络编程>> 网页设计>> form 元素内的字段 name 不要跟 form 属性名称一致

form 元素内的字段 name 不要跟 form 属性名称一致

作者:realazy 来源:realazy.org 发布时间:2008-10-22 13:25:00 

标签:form,name,名称,表单

长话短说,看这个 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

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com