Convert pseudo array in JavaScript to real array
In JavaScript, the hidden variable arguments in the function and the element collection (NodeList) obtained with getElementsByTagName are not real arrays. Methods such as push cannot be used. When necessary, they can only be converted to real arrays first. .
For arguments, you can use Array.prototype.slice.call(arguments); to achieve the purpose of conversion, but this is not possible for NodeList. It will report an error in IE8 and below. It can only be said that its JS engine has limitations. .
Therefore, if you need to convert NodeList into a real array, you need to do compatibility processing.
JavaScript setting homepage function
JavaScript collection function
基于JQuery的,你可以根据自己的需求来修改。
javascript检测元素是否支持某个属性代码
用法:
创建和使用命名空间
使用方式
以上就是本文的全部内容了,希望大家能够喜欢。