level 12
h5新特性,可以type设置成number,以及用表单会不会好一点
2021年05月12日 16点05分
2
level 6
// 面向对象的方式,仅供参考,写的匆忙,有些细节没考虑
// 构造函数
function Person(gender, height, weight, btnId, checkWeight) {
this.gender = gender; //性别
this.height = height; //身高
this.weight = weight; //体重
var _this = this; //保存对象的this
this.checkBtn = document.getElementById(btnId);//获取按钮元素
this.checkBtn.onclick = function () { //按钮的单击事件
//call的作用是改变目标函数的this
// 注意:这里的_this是new实例化出来的对象,而this是所点击的按钮对象
// checkWeight是点击按钮后执行的函数
_this.fnClick.call(this, checkWeight);
}
}
Person.prototype = {
constructor: Person,
fnClick: function () {
let gender = document.getElementById("gender").value;
let height = document.getElementById("height").value;
let weight = document.getElementById("weight").value;
// console.log(`${gender}`,`${height}`,`${weight}`);
// 性别为男时
if (gender == "男") {
if (weight > height - 100 - 3 && weight < height - 100 + 3) {
alert("您输入的男性体重合法");
}
}
// 性别为女时
if (gender == "女") {
if (weight > height - 110 - 3 && weight < height - 110 + 3) {
alert("您输入的女性体重合法");
}
}
// 输入为空时
if (gender == "" || height == "" || weight == "") {
alert("不能为空哦!继续填写吧!");
}
// 输入有误时
else {
alert("输入有误,请重新输入!");
}
}
}
window.onload = function () {
new Person(gender, height, weight, "checkBtn", this.checkWeight);
}
2021年05月13日 23点05分
4
谢谢大佬
2021年05月15日 04点05分
level 5
标准体重=身高-(100+(性别=女)*10)±3
2021年06月13日 01点06分
14
然后依据标准体重和实际体重判段
2021年06月13日 01点06分