Javascript外部文件函数赢得'我以前不工作
Javascript external file functions won't work for me, were working before
第一次发帖,所以提前为我犯的任何错误道歉。当我在Chrome/Firefox中运行此代码时,我会收到要求输入数字的初始提示框。我输入了一个数字,什么也没发生。这以前是有效的,但当我回来检查代码中的另一个文件是否存在类似问题时,它不会打开第二个警报框。
Task2.html文件
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src ="task2.js"></script>
</head>
<body>
<script>
var tempSelect = 0;
while (tempSelect != 3) {
tempSelect = prompt("1.Fahrenheit to Celcius'n2.Celcius to Fahrenheit'n3.To Exit");
if (tempSelect == 1) {
Cel();
}
else if (tempSelect == 2) {
Fahr();
}
}
</script>
</body>
</html>
Task2.js文件
function Cel() {
check = true;
var fahr = prompt("Enter the degree in Fahrenheit to convert to Celcius");
parseFloat(fahr);
while (check == isNaN(fahr)) <!--isNaN = is Not a number--><!--looping till a valid number is entered-->
{
alert("Enter a correct number!");
fahr = prompt("Enter the degree in Fahrenheit to convert to Celcius");
}
var cel = ((5.0 / 9.0) * (fahr - 32)); <!--calculations -->
parseFloat(cel);
alert("Fahr to Cel ===> " + cel); <!--Output-->
}
function Fahr() {
check = true;
var cel = prompt("Enter the degree in Celcius to convert to Fahrenheit");
parseFloat(fahr);
while (check == isNaN(cel)) {
alert("Enter a correct number!");
var cel = prompt("Enter the degree in Celcius to convert to Fahrenheit");
}
var fahr = (9.0 / 5.0 * cel) + 32;
alert("Cel to Fahr ===> " + fahr);
}
啊!我们都忽略了显而易见的一点:js文件中有HTML注释,这会导致javascript失败。
在javascript中使用/* comment */
或// comment
而不是<!-- comment -->
。
相关文章:
- 使用javascript配置文件作为handlebas博客模板,但配置不是't工作正常
- 当加载几个js文件时,defer属性应该如何工作
- 限制文件类型,大小,单次上传不'无法在jquery文件上传中工作
- HTML文件中的智能Javascript建议在Visual Studio代码更新后没有日志程序工作
- 我的代码在<脚本>标记,但没有'不能在外部文件中工作
- HTML5视频无法在chrome上工作,在服务器上托管后的IE,mov文件中的视频(quicktime格式)
- 在Alfresco中动态创建空间/文件夹的Javascript;t工作正确
- 如何让jQuery在我的Typescript文件中工作
- Django,HTML,JS:<img src=“#">可以在HTML中工作,但不能在JS文件中工作
- 在html文件中添加了多个外部javascript,其中一个停止工作
- 日食添加文件而不将其复制到工作区中
- 当我移动引用three.js的html文件时,three.js停止工作
- 安全地包装JS文件,这样当它们连接在一起时,它们仍然可以工作
- 从本地文件运行时,$.get()无法正常工作
- 无法让 javascript 从外部文件工作
- JavaScript 无法从单独的文件工作
- $render在角度1.2.2停止工作(文件验证指令)
- 纯Ajax发送其他变量与我的工作文件上传
- 如何在javascript或jquery中获得工作文件夹的物理路径
- 不能得到Dropzone.js工作?文件总是显示红色的x