IE8 and the following browser pseudo-array slice method compatible processing

Source: Internet
Author: User

A few days ago colleagues said that the array of slice method in the IE8 with compatibility issues, I consulted the MDN, the document contains IE8 and the following browser, Dom object composed of a pseudo-array call slice method does not follow the standard behavior

I made a demo and I tested it on the IE8.

<div> Ancient </div><div> German </div><div>God</div><script>var dom = document.getElementsByTagName ("div"); Console.log (Array.prototype.slice.call (DOM,1) )    < /script>

Results

Tip Dom is not a JS object in ie9+ browser without this problem. MDN Official document also gives a piece of code solution, I have a quick and easy way to solve the problem. Since DOM is not a JS object, turn it into an object is not finished, so I put the code to do the following transformation:

<div> Ancient </div><div> German </div><div>God</div><script>var dom = document.getElementsByTagName ("div"); Console.log (Array.prototype.concat.apply ([],dom). Slice (1))     </script>

Compatibility problem is so happy to solve the ~

The Goody God
Source: Http://www.cnblogs.com/wangmeijian
This article copyright belongs to the author and blog Garden All, welcome reprint, reprint please indicate source.
If you feel that this blog post for your gain, please click on the bottom right corner of the [recommended], Thank you!

IE8 and the following browser pseudo-array slice method compatible processing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.