相关疑难解决方法(0)

将HTMLCollection转换为数组的最有效方法

有没有更有效的方法将HTMLCollection转换为数组,除了迭代所述集合的内容并手动将每个项目推入数组?

javascript arrays object

343
推荐指数
7
解决办法
19万
查看次数

HTMLCollection,NodeLists和对象数组之间的区别

在DOM方面,我一直对HTMLCollections,对象和数组感到困惑.例如...

  1. document.getElementsByTagName("td")和之间有什么区别$("td")
  2. $("#myTable")并且$("td")是对象(jQuery对象).为什么console.log还会在它们旁边显示DOM元素数组,它们不是对象而不是数组?
  3. 什么是难以捉摸的"NodeLists",我如何选择一个?

还请提供以下脚本的任何解释.

谢谢

[123,"abc",321,"cba"]=[123,"abc",321,"cba"]
{123:123,abc:"abc",321:321,cba:"cba"}=Object { 123=123, abc="abc", 321=321, more...}
Node= Node { ELEMENT_NODE=1, ATTRIBUTE_NODE=2, TEXT_NODE=3, more...}
document.links= HTMLCollection[a #, a #]
document.getElementById("myTable")= <table id="myTable">
document.getElementsByClassName("myRow")= HTMLCollection[tr.myRow, tr.myRow]
document.getElementsByTagName("td")= HTMLCollection[td, td, td, td]
$("#myTable")= Object[table#myTable]
$("td")= Object[td, td, td, td]


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
    <head> 
        <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" /> 
        <title>Collections?</title>  
        <script src="http://code.jquery.com/jquery-latest.js" type="text/javascript"></script> 
        <script type="text/javascript">
            $(function(){
                console.log('[123,"abc",321,"cba"]=',[123,"abc",321,"cba"]);
                console.log('{123:123,abc:"abc",321:321,cba:"cba"}=',{123:123,abc:"abc",321:321,cba:"cba"});
                console.log('Node=',Node);
                console.log('document.links=',document.links);
                console.log('document.getElementById("myTable")=',document.getElementById("myTable"));
                console.log('document.getElementsByClassName("myRow")=',document.getElementsByClassName("myRow"))
                console.log('document.getElementsByTagName("td")=',document.getElementsByTagName("td"));
                console.log('$("#myTable")=',$("#myTable")); …
Run Code Online (Sandbox Code Playgroud)

javascript jquery dom

79
推荐指数
4
解决办法
5万
查看次数

javascript - Array和类似Array的对象之间的区别

我在javascript中经常遇到"Array-Like Object"这个术语.它是什么 ?它和普通阵列有什么区别?什么是类似数组的对象和普通对象之间的区别?

javascript arrays

26
推荐指数
2
解决办法
8984
查看次数

标签 统计

javascript ×3

arrays ×2

dom ×1

jquery ×1

object ×1