开发者

Is it true IE 8 doesn't support .length property?

Is it true IE 8 doesn't support .length property?

I have to use a picture, Stackoverflow says:

Oops! Your question couldn't be submitted because: Your post appears to contain code that is not properly formatted as code. Please indent all code by 4 spaces using t开发者_开发知识库he code toolbar button or the CTRL+K keyboard shortcut. For more editing help, click the [?] toolbar icon.

The screenshot was taken from Stackoverflow's form.


Internet Explorer has no problems with the length property. If it didn't support it, then it would report undefined not 0.

The HTML is invalid, there is no name attribute for the div element. Internet Explorer is just error recovering in a different way to Firefox and not matching the div elements with getElementsByName

Elements that support both the NAME attribute and the ID attribute are included in the collection returned by the getElementsByName method, but elements with a NAME expando are not included in the collection.

— MSDN getElementsByNameMethod

Use a class instead. Internet Explorer 8 doesn't have a native getElementsByClassName, but there are no shortage of cross-browser implementations or you could use a selector engine or a big library that includes one such as YUI or jQuery.


getElementsByName is for use on input HTML elements - DIV elements do not have name attributes


Your problem is not that .length is not working on IE, but that getElementByName() is not working on IE... : getElementsByName in IE7

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜