0
由於標題狀態我試圖將英寸轉換爲英尺,而不是像5.02顯示小數,我希望它顯示5'2「例如。我想創建一個從英寸到英尺的轉換器,但只顯示小數點
我想要的「轉換腳」顯示,他們的標準ft'inches」格式。
我的代碼HTML
<form class="form-inline">
<div class="form-group">
<label for="width">Width:</label>
<input type="text" class="form-control" id="width" placeholder="">
</div>
<div class="form-group">
<label for="height">Height:</label>
<input type="text" class="form-control" id="height" placeholder="">
</div>
<div class="form-group">
<label for="measurement">Measurement:</label>
<select class="form-control" id="measurement" placeholder="">
<option value="1">Inches</option>
<option value="2">Feet</option>
</select>
</div>
<div class="form-group">
<input type="button" class="btn btn-info" value="Submit" onclick="myFunction()">
</div>
<div class="form-group">
<input type="button" class="btn btn-danger" value="Clear" onclick="clearFunction()">
</div>
</form>
<table class="table table-bordered table-background" id="contentTable">
<thead>
<tr>
<th>Type</th>
<th>Surface Area</th>
<th>Conversion to Inches</th>
<th>Conversion to Feet</th>
</tr>
</thead>
<tbody>
<tr>
<td id="type"></td>
<td id="area"></td>
<td id="conInch"></td>
<td id="conFeet"></td>
</tr>
</tbody>
</table>
這裏是我的JavaScript
function myFunction()
{
var width = document.getElementById('width').value;
var height = document.getElementById('height').value;
var measurment;
var area;
var widthFeet;
var heightFeet;
var widthInches;
var heightFeet;
var type;
if(document.getElementById('measurement').value == 1){
measurment = 1;
type = "Inches"
area = width * height;
widthFeet = width/12;
heightFeet = height/12;
widthInches = width;
heightInches = height;
} else if(document.getElementById('measurement').value == 2){
measurment = 2;
type = "Feet"
area = width * height;
widthInches = width * 12;
heightInches = height * 12;
widthFeet = width;
heightFeet = height;
}
document.getElementById('type').innerHTML = type;
document.getElementById('area').innerHTML = area + "(" + width + "x" + height + ")";
document.getElementById('conInch').innerHTML = widthInches + " X " + heightInches;
document.getElementById('conFeet').innerHTML = widthFeet.toFixed(2) + " X " + heightFeet.toFixed(2);
}
function clearFunction(){
document.getElementById('type').innerHTML = "";
document.getElementById('area').innerHTML = "";
document.getElementById('conInch').innerHTML = "";
document.getElementById('conFeet').innerHTML = "";
}
在編程中查找模數...它是javascript中的%運算符。 –
是的,我知道%是什麼以及如何使用它,但我不認爲這是一個解決方案,因爲其餘的不是英寸。所以12 x 13英寸顯示1 x 1.0833333,其餘的這裏是不正確的。 – Charles
13 X 14應該是1'1「X 1'2」... 2「來自14%12 –