使用Google Chrome来调试和编辑嵌入HTML页面中的JavaScript [英] Using Google Chrome to debug and edit javascript embedded in HTML page

查看:432
本文介绍了使用Google Chrome来调试和编辑嵌入HTML页面中的JavaScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果JavaScript位于.js文件中,Chrome开发人员工具可让您在浏览器中编辑JavaScript。但是,似乎不允许我编辑嵌入在HTML页面中的JavaScript。即:

Chrome developer tools allows you to edit javascript in the browser if the javascript is in a .js file. However, it does not seem to allow me to edit javascript that is embedded in an HTML page. ie:

<script type="text/javascript> 
// code here that I want to debug/edit
</script> 

对我来说这是一个很大的问题,因为我有在某个页面中嵌入一些javascript。

This is a big problem for me as I have quite a bit of embedded javascript in a certain page.

与此问题类似:编辑JavaScript块的网页... live ,但这是关于firefox,而不是chrome。

Similar to this question: Edit JavaScript blocks of web page... live but this is about firefox, not chrome.

如何使用Google Chrome开发者工具编辑嵌入HTML页面的JavaScript?

推荐答案

允许这样做,在开发者工具窗口的资源标签中选择HTML文件,您将看到HTML而不是javascript,并且只需在< script> 标签,还可以添加 debugger; 命令来编写要调试的脚本,例如:

Actually chrome allows to do that, choose HTML files in Sources tab in Developer tools window. You will see HTML instead of javascript and simply add breakpoints in the <script> tags. Also you can add debugger; command to script what you want to debug. For example:

<script>
 // some code
 debugger; // This is your breakpoint
 // other code you will able to debugg
</script>

不要忘记删除调试器; 当您要发布您的网站时。

Don't forget to remove debugger;'s when you want to release your website.

这篇关于使用Google Chrome来调试和编辑嵌入HTML页面中的JavaScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆