我试图检查CSS属性从输入到表格单元格。输入在点击时出现,在失去焦点时消失,就像我试图检查它一样。 当我移动到另一个窗口(检查器)时,我如何做到不失去焦点?


当前回答

将以下Javascript代码粘贴到浏览器开发控制台:

// Delayed console log of parent element with disappearing child element(s)
// Once code is trigger, you have 3 seconds to trigger the hidden element before it snapshots.
// The hidden elements should appear in the console ready to inspect.

var timer = 3000; //time before snapshot
var parent_of_element_to_inspect = 'div.elementcontainer'; //container of element to snapshot
setTimeout(function(){
 console.log(document.querySelector(parent_of_element_to_inspect).cloneNode(true));
},timer);

其他回答

如果所有这些都失败了,在控制台中输入以下内容:

setTimeout(() => { debugger; }, 5000)

然后,您有5秒钟的时间(或将值更改为其他任何值)来显示您想要调试的任何内容。

其他的答案都对我不起作用——DOM树在脚本暂停之前一直被修改(即我关心的东西消失了)。

我有一个更快的解决办法,因为我不太擅长使用工具,这是我所做的。

event.originalEvent.preventDefault();
event.originalEvent.stopImmediatePropagation();
event.originalEvent.stopPropagation();

在chrome devtools中单击元素的右侧;-)

如果你打开Chrome DevTools,然后使用键盘快捷键触发元素检查器,它应该可以解决这个问题。

Mac: Cmd+Opt+J,然后Cmd+Opt+C

Windows:先按Ctrl+Shift+J,再按Ctrl+Shift+C

[

将以下Javascript代码粘贴到浏览器开发控制台:

// Delayed console log of parent element with disappearing child element(s)
// Once code is trigger, you have 3 seconds to trigger the hidden element before it snapshots.
// The hidden elements should appear in the console ready to inspect.

var timer = 3000; //time before snapshot
var parent_of_element_to_inspect = 'div.elementcontainer'; //container of element to snapshot
setTimeout(function(){
 console.log(document.querySelector(parent_of_element_to_inspect).cloneNode(true));
},timer);