debugging - Visual Studio Code - 使用 Chrome 进行调试 - 断点在开始时运行,而不是在遇到时
问题描述
编辑:我找到了解决方案。由于其他人可能会犯同样的错误,我将答案放在底部。
我正在使用 Visual Studio 代码。我是新手。
我安装了 Debugger For Chrome 和 Debugger For Edge。
我已经安装了 Live Server。
我有launch.json
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch Chrome",
"request": "launch",
"type": "pwa-chrome",
"url": "http://127.0.0.1:5500/a.html",
"webRoot": "${workspaceFolder}"
}
]
}
我有我的基本 html 文件:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<button onclick="myfunc()">Click</button>
</body>
<script>
function myfunc(){
alert("clicked");
}
</script>
</html>
我的断点就行了alert("clicked");
。
我单击蜘蛛左侧的调试图标,然后单击绿色按钮启动。
现在奇怪的一点:
alert
即使没有按下按钮,程序也会立即启动并在线中断。
我继续。
但是当我单击按钮并期望遇到断点时。它不是。警报在没有中断的情况下发生。
有人知道我在做什么错吗?
解决方案:
它不喜欢<script>
身体的外部。如果您将 html 文件更改为包含<script>
正文,则它可以正常工作。
像这样:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<button onclick="myfunc()">Click</button>
<script>
function myfunc(){
alert("clicked");
}
</script>
</body>
</html>
解决方案
我发现出了什么问题。
它不喜欢身体的外部。如果您将 html 文件更改为包含正文,则它可以正常工作。
像这样:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<button onclick="myfunc()">Click</button>
<script>
function myfunc(){
alert("clicked");
}
</script>
</body>
</html>
推荐阅读
- render - Ant design Table 不会使用 Nextjs 重新渲染
- machine-learning - 了解 LSTM 架构中的密集层(标签和 logits)
- xamarin - 用户在应用程序中崩溃。我不明白是什么原因
- python - 也是第二个字符串中的子字符串的最长前缀
- c# - 捕获字符串并将其作为列表传递给参数
- python - 在 Django 中使用 Textfield 和 charfield 模型时出错
- javascript - 如何为 p5js 创建动画类库
- javascript - 如何添加对特定消息的反应?
- git - 将 git last 标记获取到 Azure 管道变量中
- python - 如何将枚举列表分成字符串python