问题
When we type $
in chrome console it returns a function. I am sure it's not jQuery's $
.
If I want to use jQuery in console, What is the best way to trigger jQuery in chrome console as $
.
回答1:
$
is an alias for document.querySelector. In the same vein there is $$ which is an alias for document.querySelectorAll.
It is defined in the Command line (console) api.
Command Line API Reference
The Command Line API contains a collection of convenience functions for performing common tasks: selecting and inspecting DOM elements, displaying data in readable format, stopping and starting the profiler, and monitoring DOM events.
If you have $
defined on the page as a global (perhaps by using jQuery), you'll get that global, not the command-line built-in.
There are other handy functions defined there.
To run jQuery, without having it in the page source code, you may find Chrome extensions to be handy, or simply copy-paste the jQuery source code in the console.
来源:https://stackoverflow.com/questions/45757627/what-is-in-chrome-console