我一直在學習js對象的工作,所以我決定看看會發生什麼,如果我試圖將jQuery對象分解成它的組件。我想知道是否有一個更好,更細緻的方式來做到這一點,或者有一些其他的技巧,可能是教育:轉儲JQuery對象
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>JQuery Dump</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<style type="text/css">
ol li {
font-weight:bold
}
ol li ul {
margin-bottom:0px
}
ol li ul li {
display:inline-block;
}
ol li ul li {
font-weight:normal;
list-style:none;
margin-right:8px;
}
</style>
</head>
<body>
<ol>
<script>
var x = "";
for(var i in jQuery) {
x += ("<li>" + i + "<ul>");
for(var j in jQuery[i]) {
x += ("<li><pre>" + j + "</pre></li>");
}
x += ("</ul></li>");
}
document.write(x);
</script>
</ol>
</body>
</html>
要快速輕鬆地檢查jQuery對象,只需將其記錄下來即可。如果您打開Firebug或Chrome開發者工具,請選擇控制檯選項卡,然後輸入'console.log(jqObject)',它將打印出具有其所有屬性的對象。它將顯示屬性旁邊的三角形以展開它們並進一步檢查其內容。 – Zhihao 2013-03-26 06:50:54
我已經更新了我的答案,以產生更接近於您開始的輸出(但是遞歸)的輸出 – 2013-03-26 08:46:55
另請注意,您會發現許多屬性用於內部使用或提供非常高級的可擴展性。爲了學習jQuery,你應該看看[docs](http://api.jquery.com/),瞭解你可能會讀[jQuery]的jQuery(https://github.com/jquery/jquery ) – Bergi 2013-03-26 09:23:08