jquery怎么将类数组对象转换为数组?
程序代码如下:
<script type="text/javascript">
function test(){
alert(arguments)
arguments = Array.prototype.slice.call(arguments);
alert(arguments instanceof Array);
alert(arguments)
}
test(1,2,3,4);
//※※※※※※※※※※※测试2※※※※※※※※※※※※※※
var htmlcollection = document.getElementsByTagName("h3");
alert(htmlcollection)
try{
htmlcollection = Array.prototype.slice.call(htmlcollection);
alert(htmlcollection instanceof Array);
alert(htmlcollection);
}catch(e){
alert(e)
}
//※※※※※※※※※※※测试3※※※※※※※※※※※※※※
var sheets = document.styleSheets;
alert(sheets)
try{
sheets = Array.prototype.slice.call(sheets);
alert(sheets instanceof Array);
alert(sheets);
}catch(e){
alert(e)
}
alert(arrayLike)
arrayLike = Array.prototype.slice.call(arrayLike);
alert(arrayLike instanceof Array);
alert(arrayLike);
</script>