Posts Tagged getElementById
小心IE7 javascript 的 getElementById Method 的問題
Posted by Chowky in Articles, Jquery, Mootools, News on August 6, 2009
1. 要注意用相同的 name and id attributes for Form Inputs
chowky 很久以前都覺得奇怪,不過這是因為IE系列和其他不同的browser的分別,ie 是會search 左name attribute先,再search id attribute,但是其他browser是不會的。所以兩個attributes 都要用相同的名。避免發生問題
1 | <input type="text" name="full_address" id="address" value="5th Avenue" /> |
2. 不要放name attribute 在form tag 入面。
和上面的情況非常相似,要避免IE的問題。
不過chowky 不知道name 是deprecated (哈)
Also, the name attribute for forms is deprecated in XHTML Strict, so it’s not best practice anyhow. The name attribute was added to form elements in older sites, so if you’re trying to debug a getElementById issue in IE7 on some inherited code, there could be a conflict occurring due to this fact.
1 2 | <form id="contact_form"> </form> |


Recent Comments