问题
In Firebug, I can type my own JavaScript in the console tab and execute it. Is there a way to type JavaScript in Chrome Developer Tools and execute it?
回答1:
- Go to
chrome://flags/
, enable the "Enable Developer Tools experiments" flag and restart Chrome (or start it with the--enable-devtools-experiments
command-line flag.) - Open DevTools, go to the
Settings
dialog, switch to theExperiments
tab. - Enable the "Snippets support" experiment, close and reopen DevTools.
- Go to the
Sources
panel. In the left-hand navigator sidebar, switch to theSnippets
tab . - Right-click in the [empty] tree in this tab, select the
New
context menu item. - Give the new snippet any name you like and type the snippet body.
- Once done, click the
Run
(>
) button in the status bar to execute the snippet body. You can set breakpoints in snippets and debug them as ordinary scripts.
回答2:
Step 1: Open Google chrome Dev tool [ Press f12 ]
Step 2: Click on Sources tab
Step 3: On left side panel, Click on Snippets tab (may be hidden, if so click >> and it will appear)
Step 4: To create new snippet click + New snippet or right-click within the Navigator, and then select New
Step 5: Develop your code into middle pane and save it.
Step 6: To run Snippet, there are three ways
A: Ctrl + Enter
B: Click on Run button [ Into Right-side panel, Top-Left button ]
C: Right-click on the snippet filename (in the pane on the left that lists
all your snippets) and select Run.
回答3:
Recent Chrome Using Chrome 50, juste open the "Console" tab and start typing and executing your code at the bottom of the console.
Arrow up, recalls the code, ctrl-enter gives you a new line:
回答4:
You can't debug Javascript, but you can execute it (including jquery) in a REPL in the chrome inspector.
- Open the inspector
- Click the button at the bottom left with 3 lines - its tooltip is "show console"
- Type your javascript and press enter
Note you usually have to go to the Sources tab and click the "pause script execution" button for your javascript to get evaluated.
来源:https://stackoverflow.com/questions/13792553/write-javascript-in-chrome-developer-tools