나는 자바 스크립트와 메신저에 BMI 계산기를 처음 사용합니다. 메신저 자바 스크립트에서 계산을 생성하는 클래스를 만들고있어. 현재 사용자는 높이 (피트 및 인치)와 무게를 입력 할 수 있습니다. 내 수업 내에서 메소드를 실행할 때. 입력에서 값을 가져 오는 대신 this.feet = null을 계속 말합니다. 내 자바 스크립트 코드는 아래 있습니다. result() 내 HTML 제출 단추입니다.자바 스크립트 클래스 내에서 html 입력 값 받기
function calculator(feet,inches,weight) {
this.feet = feet.value;
this.inches = inches.value;
this.weight = weight.value;
this.validateInput = function() {
var errors = [];
if(isNaN(this.feet) || this.feet < 0) {
errors.push("Feet");
}
else {
return this.feet
};
if(isNaN(this.inches) || this.inches < 0 || this.inches > 11) {
errors.push("Inches")
}
else {
return this.inches;
};
if(isNaN(this.weight) || this.weight < 0) {
errors.push("Weight");
}
else {
return this.weight
}
};
this.inchesConverter = function() {
this.feet = parseFloat(feet);
this.inches = parseFloat(inches);
return parseInt(this.feet*12+this.inches);
};
this.bmi = function() {
var height = this.inchesConverter();
var validater = this.validateInput();
for(r = 0; r < errors.length; r++){
if(errors.length > 0) {
return errors[r] + " must be a valid positive number.";
}
else {
parseFloat((validateWeight * 703)/(Math.pow(height, 2))).toFixed(1);
}
}
};
};
var getWeight = document.getElementById('txtWeight');
var getFeet = document.getElementById('txtHeightFeet');
var getInches = document.getElementById('txtHeightInches');
var test = new calculator(getFeet, getInches, getWeight);
function result() {
document.getElementById("lblBMI").innerHTML(test.bmi());
}
질문에 대한 답변을 드릴 수 있습니까? – Teemu
@ Teemu - [* ed 6 *] (https://people.mozilla.org/~jorendorff/es6-draft.html) (일종의 표준이되는 경우)에 정렬됩니다. ;-) – RobG
문제에 대한 도움을 얻으려면'validateInput' 내의 콘솔에'this'를 기록하여 실제로 무엇을 참조하고 있는지 확인하십시오. – Teemu