問題描述
在 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>]
或
[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()
有誰知道我如何才能恢復 Google Chrome 控制臺的原始設置?
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 或 鉻基替代品)
- 通過添加您自己的
function log()
覆蓋 - 在某些情況下使用 outerHTML 或升級到 chrome 25.0.1323.1 (dev channel) where console.log($(#Selector)[0]);再次返回 outHMTL(見下文).
console.log()
根據 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
用戶 brentonsrine 讓我意識到我的 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 channel (25.0.1323.1) 和兩個基于鉻的版本對其進行了測試(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 對象寫入 最近的 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 中相同的輸出,他可以提交錯誤.這兩個 bugs 可以用作模板來提出更改請求.
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的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!