在Chrome开发人员工具中编写JavaScript [英] Write JavaScript in Chrome developer tools
本文介绍了在Chrome开发人员工具中编写JavaScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Firebug中,我可以在控制台选项卡中键入自己的JavaScript并执行它.有没有一种方法可以在Chrome开发者工具中键入JavaScript并执行它?
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?
推荐答案
- 转到
chrome://flags/
,启用启用开发人员工具实验"标志,然后重新启动Chrome(或使用--enable-devtools-experiments
命令行标志启动它.) - 打开DevTools,转到
Settings
对话框,切换到Experiments
选项卡. - 启用代码段支持"实验,关闭并重新打开DevTools.
- 转到
Sources
面板.在左侧导航器的侧栏中,切换到Snippets
标签. - 右键单击此选项卡中的[空白]树,选择
New
上下文菜单项. - 为新代码段提供任何您喜欢的名称,然后输入代码段正文.
- 完成后,单击状态栏中的
Run
(>
)按钮以执行代码段主体.您可以在摘要中设置断点,并将其作为普通脚本进行调试.
- 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.
这篇关于在Chrome开发人员工具中编写JavaScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文