IE 的 document.getElementsByName 有 BUG

posted on 2010-03-05 18:51:35+08:00 by david
http://wangblog.org/2010/03/ie-documentgetelementsbyname-bug.html
  1. <div id="test"></div>
  2. <script type="text/JavaScript">
  3. var _input;
  4. var _test = document.getElementById('test');
  5. _input = document.createElement('input');
  6. _input.type = 'text';
  7. _input.name = 'test[1]';
  8. _input.value = 'test1';
  9. _test.appendChild(_input);
  10. _input = document.createElement('input');
  11. _input.type = 'text';
  12. _input.name = 'test[2]';
  13. _input.id = 'test[2]';
  14. _input.value = 'test2';
  15. _test.appendChild(_input);
  16. try{
  17. alert(document.getElementsByName('test[1]')[0].value);
  18. }catch(e){
  19. alert(e.toString());
  20. }
  21. alert(document.getElementsByName('test[2]')[0].value);
  22. </script>

All Code Snippets

Hot Code Snippets

New Code Snippets