簡體   English   中英

如何在控制台中將HTML元素存儲為全局變量

[英]How to store HTML Elements as global variable in the console

使用chrome開發工具時,對於使用console.log登錄到控制台的任何變量,我都可以右鍵單擊並選擇“ Store as global variable ,除非登錄HTML元素。

我找到了一種解決方法:如果使用console.log([el])而不是console.log(el) ,則可以將數組保存到全局變量,然后使用temp1[0]訪問元素。

這似乎有點麻煩。 還有另一種方法可以在console.log的全局變量中存儲console.log ged元素嗎?

您可以使用$$(selector)

ƒ $$(selector, [startNode]) { [Command Line API] }

然后使用問題中描述的步驟。

$_返回控制台中最后記錄的項目。
但是請注意,如果使用console.log() ,它可能會返回undefined ,因為如果您使用console.log('hi!'); ,那么它也會返回undefined 解決方法:

/*just type value instead of console.log*/
'hello!';
var text=$_;
/*If you cannot do this, just log it in this way:*/
x.valueOf();
var xContent=$_;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM