html - 用于计算的无线电代码和数字输入以及您要求的文件的错误不存在
问题描述
我试图学习 Javascript。我想同时输入无线电代码和数字进行计算。我在https://validator.w3.org/上检查了我的代码并解决了任何问题,但是当我运行它时,我看到错误“您要求的文件不存在”。因为我是初学者,如果能帮助我并重写我的代码,我会很高兴。关于,马赫迪普尔
<!DOCTYPE html>
<html lang="fa">
<head>
<title>Title</title>
</head>
<form onsubmit="return calcBMI();">
<p>توجه. مقدار رنگ محاسبه شده در این سیستم برای پایده سازی یک لایه رنگ است</p><br>
<p>لطفا رنگ مورد نظر خود را انتخاب کنید</p>
<label>
<input type="radio" id="bmi-metric" name="bmi-measure" onchange="measureBMI()" checked/> اکریلیک
</label>
<label>
<input type="radio" id="bmi-imperial" name="bmi-measure" onchange="measureBMI()"/> پلاستیک
</label>
<label>
<input type="radio" id="bmi-oil" name="bmi-measure" onchange="measureBMI()" checked/> روغنی
</label>
<br><br><br>
<p>لطفا طول، عرض و ارتفاع اتاق را وارد کنید</p>
طـول اتــاق
<input id="bmi-weight" type="number" min="1" placeholder="سانتی متر" required/>
<span id="bmi-weight-unit"> *</span><br><br>
عرض اتاق
<input id="bmi-height" type="number" min="1" placeholder="سانتی متر" required />
<span id="bmi-height-unit"> *</span><br><br>
ارتفاع اتـاق
<input id="bmi-room" type="number" min="1" placeholder="سانتی متر" required/>
<span id="bmi-room-unit"> *</span><br><br><br>
<p>لطفا تعداد درب و پنجره های موجود در اتاق را وارد کنید. در صورت عدم وجود درب یا پنجره عدد صفر را وارد کنید </p>
تعداد درب
<input id="bmi-door" type="number" min="1" required/>
<span id="bmi-door-unit"> *</span><br><br>
تعداد پنجره
<input id="bmi-window" type="number" min="1" required/>
<span id="bmi-window-unit"> *</span><br><br><br>
<input type="submit" value="محاسبه رنگ مورد نیاز"/>
<div id="bmi-results"></div>
</form>
<script>
function measureBMI () {
// true = اکریلیک , false = پلاستیک , else = روغنی
let unit = document.getElementById("bmi-metric").checked,
weight = document.getElementById("bmi-weight"),
weightu = document.getElementById("bmi-weight-unit"),
height = document.getElementById("bmi-height"),
heightu = document.getElementById("bmi-height-unit");
room = document.getElementById("bmi-room"),
roomu = document.getElementById("bmi-room-unit"),
door = document.getElementById("bmi-door"),
dooru = document.getElementById("bmi-door-unit"),
windoww = document.getElementById("bmi-window"),
windowu = document.getElementById("bmi-window-unit"),
}
function calcBMI () {
// (A) Get elements
let bmi = null,
unit = document.getElementById("bmi-metric").checked, // true = اکریلیک , false = پلاستیک , else = روغنی
weight = parseInt(document.getElementById("bmi-weight").value),
height = parseInt(document.getElementById("bmi-height").value),
room= parseInt(document.getElementById("bmi-room").value),
door= parseInt(document.getElementById("bmi-door").value),
windoww= parseInt(document.getElementById("bmi-window").value),
results = document.getElementById("bmi-results");
// (B) Calculate BMI
// Metric BMI = Mass (kg) / Height (m) square
if (unit) {
bmi = (2*(weight * room + height * room)-(door*90*210+window*150*150))/13;
}
// Imperial BMI = 703 X Mass (lbs) / Height (in) square
else if {
bmi = (2*(weight * room + height * room)-(door*90*210+window*150*150))/8;
}
else {
bmi = (2*(weight * room + height * room)-(door*90*210+window*150*150))/7;
}
// Round off
bmi = Math.round(bmi * 100) / 100; // Round off 2 decimal places
// (C) Show Results
if (bmi < 18.5) {
results.innerHTML = bmi + " - Underweight";
} else if (bmi < 25) {
results.innerHTML = bmi + " - Normal weight";
} else if (bmi < 30) {
results.innerHTML = bmi + " - Pre-obesity";
} else if (bmi < 35) {
results.innerHTML = bmi + " - Obesity class I";
} else if (bmi < 40) {
results.innerHTML = bmi + " - Obesity class II";
} else {
results.innerHTML = bmi + " - Obesity class III";
}
return false;
}
</script>
解决方案
您的代码中有两个语法错误。
- 在函数的最后一行,您
measureBMI()
有:
windowu = document.getElementById("bmi-window-unit"),
应该有分号;
而不是逗号,
。
在同一函数的这一行中也可能应该有逗号而不是分号。但是我不确定您使用此功能的目的是什么。目前,您正在将元素分配给变量,但您对这些变量无所事事。let
关键字使这些变量仅在函数范围内可见measureBMI()
。
heightu = document.getElementById("bmi-height-unit");
- 在您的
calcBMI()
功能中,您有:
if (unit) {
bmi = (2*(weight * room + height * room)-(door*90*210+window*150*150))/13;
}
// Imperial BMI = 703 X Mass (lbs) / Height (in) square
else if {
bmi = (2*(weight * room + height * room)-(door*90*210+window*150*150))/8;
}
else {
bmi = (2*(weight * room + height * room)-(door*90*210+window*150*150))/7;
}
您缺少您的条件else if (condition) {
。
由于这些语法错误,此 javascript 无法运行,并且当您尝试提交表单时calcBMI()
未定义。因此,浏览器尝试以标准方式提交表单。
推荐阅读
- php - DB Builder 上的 Laravel 范围
- java - 使用maven插件过滤资源时可以检索pom文件中的嵌套数据吗?
- node.js - Typeorm - 无法连接到 postgres
- jackson - 使用 Jackson 反序列化由 Eclipselink Moxy 创建的 JSON
- swift - 从 AVSpeechSynthesisVoice 获取国家列表
- reactjs - 从 react js 联系表单发送电子邮件
- java - 使用 JavaAPI 将 CSV 文件批量上传到 Elasticsearch
- python-3.x - 在 boto3 python 3.8 lambda 中获取请求失败
- azure-active-directory - 使用“/directoryObjects/validateProperties”API 时出错:提供的实体类型无效
- java - 如何在启动其他活动并通过按钮启动该活动后再次停止已经运行的媒体播放器?