2016-10-12 105 views
-2
Feet'inches

大家好,我使用的身高和體重它的正常工作,但我想轉換進入高度(釐米)的Feet'inches轉換身高(釐米),以使用Javascript

HTML

計算BMI
//height in Centimeter 
<input type="number" onblur="myFunction()" min="0" name="height" id=height_' + len + ' class="txtInput2 personalize-form box-width" required/> 

//Weight 
<input type="number" onblur="myFunction()" min="0" name="weight" id=weight_' + len + ' class="txtInput4 personalize-form box-width" required/> 

的Javascript

function myFunction(){ 
    var height = document.getElementById("height_1").value; 
    var weight = document.getElementById("weight_1").value; 

    if(weight > 0 && height > 0){ 
    var finalBmi = weight/(height/100*height/100) 
    document.bmiForm.bmi.value = finalBmi 
    if(finalBmi < 18.5){ 
    var health= document.bmiForm.meaning.value = "UW" 
    } 

    if(finalBmi > 18.5 && finalBmi < 25){ 
     var health1= document.bmiForm.meaning.value = "IW" 
     alert(health1); 
    } 
    if(finalBmi > 25){ 
    var health2= document.bmiForm.meaning.value = "OW" 
     alert(health2); 
    } 
    } 
else{ 
    //alert("Please Fill in everything correctly") 
} 
} 
+1

和一英尺12英寸,應該是微不足道的數學?首先寫在紙上,然後寫JS代碼來做同樣的計算 – adeneo

+0

它已經在堆棧中討論過。請參考[this](http://stackoverflow.com/questions/16541392/convert-centimeters-to-英寸) – Thala

回答

1

試試這個

function toFeet(n) { 
     var realFeet = ((n*0.393700)/12); 
     var feet = Math.floor(realFeet); 
     var inches = Math.round((realFeet - feet) * 12); 
     return feet + "&prime;" + inches + '&Prime;'; 
    } 
+0

您可以參考重複的問題。這個答案沒有增加任何價值。 –

+0

@RazvanDumitru上一個問題does not have acceptable answer !!! –

+3

這一個 - > http://stackoverflow.com/questions/13723585/javascript-jquery-display-inches-in-feet-and-inches – adeneo

相關問題