我正在尝试从我的HTML页面调用一个简单的javascript函数。 javascript函数将使用“ lib.js”文件解密,并且会发出警报。
未捕获的ReferenceError:未在HTMLInputElement.onclick错误中定义解密函数
<script>
//code
// bfp calculator
function bfpCalc() {
'use strict'
var bfp = 0;
var density = 0
var gender = parseFloat(document.bfpForm.gender.value);
var height = parseFloat(document.bfpForm.height.value);
var waist = parseFloat(document.bfpForm.waist.value);
var abdomen = parseFloat(document.bfpForm.abdomen.value);
var neck = parseFloat(document.bfpForm.neck.value);
var hip = parseFloat(document.bfpForm.hip.value);
if (gender == 1) {
if (neck == '' || abdomen == '') {
density = "SMSH"
} else {
let calc = 0
calc = 1.0324 + (0.15456 * Math.log10(height)) - (0.19077 * Math.log10(abdomen - neck))
density = calc
// density = parseFloat(calc).toFixed(9)
}
} else if (gender == 0) {
if (neck == '' || waist == '' || hip == '') {
density = "SMSH"
} else {
let calc = 0
calc = 1.29579 + (0.221 * parseFloat(Math.log10(height)).toFixed(9)) - (0.35004 * parseFloat(Math.log10(hip + waist - neck)).toFixed(9))
density = calc
}
}
if (density == "SMSH") {
bfp = "SMSH"
} else if (parseFloat((4.95 / density) - 4.5).toFixed(4) > 0.1) {
if (density == "SMSH") {
bfp = "SMSH"
} else {
bfp = parseFloat(((4.95 / density) - 4.5)*100).toFixed(2)
}
}
document.bfpForm.bfp.value = bfp + '%';
if(bfp <= 5 && bfp >= 2 && gender == 1 ){
document.bfpForm.meaning.value = "چربی ضروری";
}
if(bfp <= 13 && bfp >= 6 && gender == 1 ){
document.bfpForm.meaning.value = "ورزشکاران";
}
if( bfp > 17 && bfp < 14){
document.bfpForm.meaning.value = "تناسب اندام";
}
if(bfp <= 24 && bfp >= 18 && gender == 1 ){
document.bfpForm.meaning.value = "متوسط";
}
if(bfp >= 25 && gender == 1 ){
document.bfpForm.meaning.value = "چاق";
}
if(bfp <= 13 && bfp >= 10 && gender == 0 ){
document.bfpForm.meaning.value = "چربی ضروری";
}
if(bfp <= 20 && bfp >= 14 && gender == 0 ){
document.bfpForm.meaning.value = "ورزشکاران";
}
if( bfp > 24 && bfp < 21){
document.bfpForm.meaning.value = "تناسب اندام";
}
if(bfp <= 31 && bfp >= 25 && gender == 0 ){
document.bfpForm.meaning.value = "متوسط";
}
if(bfp >= 32 && gender == 0 ){
document.bfpForm.meaning.value = "چاق";
}
}
else{
alert("لطفا فیلد ها را به درستی وارد کنید");
}
}
</script>
<form name="bfpForm">
<label class="text-center" for="gender">جنسیت</label>
<select id="p-gender" class="pull-right p-gender-select text-right pt-10 text-center" name="gender">
<option value="1">مرد</option>
<option value="0">زن</option>
</select>
<label class="p-height-label" for="height">قد</label>
<input id="p-height" class="form-control p-gender-select text-center" min="0" name="height" required="" step="0.1" type="number" />
<label class="p-neck-label" for="neck">دور گردن</label>
<input id="p-neck" class="form-control p-gender-select text-center" min="0" name="neck" required="" step="0.1" type="number" />
<label class="p-waist-label" for="waist">دور کمر</label>
<input id="p-waist" class="form-control p-gender-select text-center" min="0" name="waist" required="" step="0.1" type="number" />
<label class="p-abdomen-label" for="abdomen">دور شکم</label>
<input id="p-abdomen" class="form-control p-gender-select text-center" min="0" name="abdomen" required="" step="0.1" type="number" />
<label class="p-hip-label" for="hip">دور باسن</label>
<input id="p-hip" class="form-control p-gender-select text-center" min="0" name="hip" required="" step="0.1" type="number" />
<input type="button" value="محاسبه درصد چربی" onClick="bfpCalc()"><br />
<label for="email">درصد چربی:</label>
<input type="text" name="bfp" size="10"><br />
<label for="email">نتیجه:</label>
<input type="text" name="meaning" size="25"><br />
<input type="reset" value="محاسبه مجدد" />
</form>
<table class="table">
<thead>
<tr>
<th>وضعیت</th>
<th>مرد</th>
<th>زن</th>
</tr>
</thead>
<tbody>
<tr class="warning">
<td>چربی ضروری</td>
<td>2% - 5%</td>
<td>10% - 13%</td>
</tr>
<tr class="success">
<td>ورزشکاران</td>
<td>6% - 13%</td>
<td>14% - 20%</td>
</tr>
<tr class="success">
<td>تناسب اندام</td>
<td>14% - 17%</td>
<td>21% - 24%</td>
</tr>
<tr class="info">
<td>متوسط</td>
<td>18% - 24%</td>
<td>25% - 31%</td>
</tr>
<tr class="danger">
<td>چاق</td>
<td>+ 25%</td>
<td>+ 32%</td>
</tr>
</tbody>
</table>
我在Stackoverflow上尝试了针对相同类型问题的其他建议,但未成功。有人可以帮我找出问题的原因吗?