console.log()不输出jQuery选择对象的HTML [英] console.log() not outputting HTML of jQuery selection object

查看:479
本文介绍了console.log()不输出jQuery选择对象的HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Google Chrome中使用 console.log 时出现问题。突然,当我输出一个元素 $(this)它显示如下:

I got a problem when using console.log in Google Chrome. Suddenly when I was outputting a element like $(this) it was display like:

[<div>, context: <div>]

>

or

[jQuery.fn.jQuery.init[1]]

。 (两者来自同一行: console.log($(this))

in the console. ( Both came from the same row: console.log($(this)) )

从无处。代码没有问题。我在其他计算机上记录了完全相同的东西,并显示为:

This problem arose yesterday from nowhere. There ain't a problem with the code. I logged the exact same thing on an other computer and there it is being displayed like:

[<div class='element'></div>, ...]

更新:新的Chrome版本更改了 console.log()的输出

Update: the new Chrome version changes the output of console.log()

有人知道我可以如何回来

Does anyone know how I can get back to the original settings of Google Chrome console?

推荐答案

要回答问题:


  • 有人知道如何恢复Google Chrome控制台的原始设置吗?

没有设置可以得到console.log()的前一个输出。您可以:

There are no settings to get the former output of console.log(). You can either:


  • 降级浏览器(使用旧版本的chrome或 chromium based alternatives

  • 覆盖 console.log )

  • 在某些情况下使用outerHTML或升级到chrome 25.0 .1323.1(dev channel)其中console.log($(#Selector)[0]);

根据user916276,console.log(jQuery-Object)的输出已更改:

According to user916276 the output of console.log(jQuery-Object) has changed:

// output of console.log($jQuerObject) 
[<div class='element'></div>, ...] // in chrome <= 23
[<div>, context: <div>]            // in chrome 24

用户 brentonstrine 让我意识到,我的context.outerHTML并不总是工作。

User brentonstrine made me aware of the fact that my context.outerHTML does not always work.

我使用新示例更新了我的代码。看起来 jqObject.context.outerHTML 的存在取决于如何将jQuery-Object传递给函数。
我使用 chrome dev渠道(25.0.1323.1)和两个基于chrome的版本( 21,22)。

I updated my code with a new example. It seems that the existence of jqObject.context.outerHTML depends how you pass the jQuery-Object to the function. I tested it with chrome dev channel (25.0.1323.1) and two chromium based versions (21, 22).

console.log($(this)); // old chrome versions 
// new chrome version >23
// if you pass this to the function see my getThis(_this) function
console.log($(this).context.outerHTML); 
// if you use a jQuery selector
console.log($(this)[0]);   // at least in chrome build 25.0.1323.1

为了避免误解。这个答案是关于将一​​个jQuery对象写入 inbuild控制台的行为。 / a>最近的Google Chrome浏览器(版本24,25)。

To avoid misunderstandings. This answer is about the changed behaviour of writing a jQuery object to the inbuild console of the recent google chrome browsers (version 24, 25).

我查看了chrome源代码更改 Console.cpp 时间轴视图,以了解WebInspector 。我找不到导致 console.log()的更改行为的确切更改。我假设它与更改ConsoleView.js 2 3 。如果任何人想要启动 console.log()返回与Chrome 21,22相同的输出,他可以提出一个错误。此两个 错误可用作放置更改请求的模板。

I took a look into the chrome source code changes at the Console.cpp and in the timeline view to find out about the changes in the WebInspector. I could not find the exact change that is responsible for the changed behaviour of console.log(). I assume that it has to do with changes to ConsoleView.js, 2, 3. If anyone would like to initiate that console.log() returns the same output as in Chrome 21, 22 he could file a bug. This two bugs could be used as a template to place the change request.

这篇关于console.log()不输出jQuery选择对象的HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆