当我控制台记录 jquery 对象时,例如。
var s = $("#item");
console.log(s);
我得到了这样的东西
[div#item, context: document, selector: "#item", jquery: "1.9.1", constructor: function, init: function…]
我记得以前(大约一个月前),我会得到类似的东西:
[<div id="item">pas</div>]
这是 Chrome 本身的变化吗?或者jquery有变化?或者我实际上做了一些事情来使输出看起来不同
我发现第二个输出更容易阅读,我可以将鼠标悬停在其上并将其标记在页面上。现在我收到太多信息,很难阅读
最佳答案
我认为您注意到的是在控制台中计算 jQuery 对象与使用 console.log()
显示它之间的区别。使用大卫·托马斯的 fiddle ,在 console.log
语句上设置断点。当它停在断点处时,在控制台中输入 $s
,您将看到
[<div id="item">pas</div>]
然后继续,您将看到由 console.log()
打印的详细对象。
我不太确定 jQuery 或 Chrome 正在做什么导致了这种差异。输入 $s
时的输出似乎是 $s.toArray()
的结果,而 console.log()
显示真实的结果jQuery 对象。
更多证据表明这不是新行为 - 我刚刚链接了 11 月份的一个重复问题。
关于jquery - 为什么 Google Chrome 通过 jQuery 有不同的 console.log() 输出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16901503/