javascript - 为什么我的两个单独的脚本不能在我的 html 文档中串行运行?
问题描述
我正在尝试学习 JavaScript。我很新(本周开始)。我正在关注javascript.info提供的练习。
这是我在 Firefox 中打开的 html 代码:
<p>First, we have a prompt that incorrectly concatenates input strings.</p>
<script>
let a = prompt("First number?", 1);
let b = prompt("Second number?", 2);
alert(a + b); // 12
</script>
<p>Now we correctly cast to integer, and then do addition.</p>
<script>
let a = prompt("First number?", 1);
let b = prompt("Second number?", 2);
a = Number(a);
b = Number(b);
alert(a + b); // 3
</script>
<p>Well, that's all folks!</p>
出于某种原因,第一个脚本会运行,但第二个不会。我已经检查过了(https://www.quora.com/Can-I-call-two-JavaScript-files-in-one-HTML-file和HTML 中多个 <script> 标签的含义),看起来像他们应该按顺序运行。
解决方案
推荐阅读
- operating-system - 监视器:“在每个时间点,最多有一个线程可能正在执行它的任何方法。”
- python - Mongo 错过了捕获插入触发器
- python - 使用 spaCy nlp 分析 df 中的文档列的问题
- sql - SQL:显示孩子和兄弟/姐妹
- mongodb - MongoDB中的排序子项
- javascript - 如何从 chrome 扩展 api 获取返回值?
- angular8 - ng2-smart-table 中的 noDataMessage” 更改字体颜色并将 noDataMessage 对齐到中心
- c++ - c ++读取多维数组作为整数仅用于比较
- javascript - 为什么 do-while 不评估逻辑 &&?
- java - 如何在动态嵌套 json 响应中返回对象