DOM에 관해서는 항상 HTMLCollections, 객체 및 배열을 혼동했습니다. 예를 들어 ...
document.getElementsByTagName("td")과 의 차이점은 무엇입니까$("td")?$("#myTable")와$("td")객체 (jQuery를이 객체)입니다. console.log가 그 옆에 DOM 요소의 배열을 표시하는 이유는 무엇이며, 배열이 아니라 객체가 아닌가?- 파악하기 어려운 "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"));
console.log('$("td")=',$("td"));
});
</script>
</head>
<body>
<a href="#">Link1</a>
<a href="#">Link2</a>
<table id="myTable">
<tr class="myRow"><td>td11</td><td>td12</td></tr>
<tr class="myRow"><td>td21</td><td>td22</td></tr>
</table>
</body>
</html>






document.querySelectorAll('td')하고$('td'). (b) 근본적인 차이점은 jQuery는 무엇보다도 번호가 매겨진 HTML 요소 모음 을 포함하는 자체 유형의 객체와 함께 작동한다는 것입니다 . 이 컬렉션은 위의 어떤 것도 아니며 jQuery 객체는 본질적으로 진정한 DOM 요소를 둘러싼 래퍼 입니다.