了解如何使用 HTML 和 JavaScript 创建长度转换器。
在任意字段中键入一个值以在长度测量之间进行转换:
创建一个输入元素,可将值从一种长度测量值转换为另一种长度测量值。
<p>
<label>Feet</label>
<input id="inputFeet" type="number" placeholder="Feet"
oninput="lengthConverter(this.value)" onchange="lengthConverter(this.value)">
</p>
<p>cm: <span id="outputMeters"></span></p>
/* When the input field receives input, convert the value from feet to meters */
function lengthConverter(valNum) {
document.getElementById("outputMeters").innerHTML = valNum / 0.0022046;
}
亲自试一试 »
下表显示了如何从英尺转换为其他长度测量值:
Description | Formula | Example |
---|---|---|
Convert from Feet to Meters | m=ft/3.2808 | 尝试一下 |
Convert from Feet to Inches | in=ft*12 | 尝试一下 |
Convert from Feet to cm | cm=ft/0.032808 | 尝试一下 |
Convert from Feet to Yards | yd=ft*0.33333 | 尝试一下 |
Convert from Feet to Kilometers | km=ft/3280.8 | 尝试一下 |
Convert from Feet to Miles | mi=ft*0.00018939 | 尝试一下 |
下表显示了如何从米转换为其他长度测量值:
Description | Formula | Example |
---|---|---|
Convert from Meters to Feet | ft=m*3.2808 | 尝试一下 |
Convert from Meters to Inches | in=m*39.370 | 尝试一下 |
Convert from Meters to cm | cm=m/0.01 | 尝试一下 |
Convert from Meters to Yards | yd=m*1.0936 | 尝试一下 |
Convert from Meters to Kilometers | km=m/1000 | 尝试一下 |
Convert from Meters to Miles | mi=m*0.00062137 | 尝试一下 |
下表显示了如何从英寸转换为其他长度测量值:
Description | Formula | Example |
---|---|---|
Convert from Inches to Feet | ft=in*0.083333 | 尝试一下 |
Convert from Inches to Meters | m=in/39.370 | 尝试一下 |
Convert from Inches to cm | cm=in/0.39370 | 尝试一下 |
Convert from Inches to Yards | yd=in*0.027778 | 尝试一下 |
Convert from Inches to Kilometers | km=in/39370 | 尝试一下 |
Convert from Inches to Miles | mi=in*0.000015783 | 尝试一下 |
下表显示了如何将厘米转换为其他长度测量值:
Description | Formula | Example |
---|---|---|
Convert from cm to Feet | ft=cm*0.032808 | 尝试一下 |
Convert from cm to Meters | m=cm/100 | 尝试一下 |
Convert from cm to Inches | in=cm*0.39370 | 尝试一下 |
Convert from cm to Yards | yd=cm*0.010936 | 尝试一下 |
Convert from cm to Kilometers | km=cm/100000 | 尝试一下 |
Convert from cm to Miles | mi=cm*0.0000062137 | 尝试一下 |
下表显示了如何从码转换为其他长度测量值:
Description | Formula | Example |
---|---|---|
Convert from Yards to Feet | ft=yd*3 | 尝试一下 |
Convert from Yards to Meters | m=yd/1.0936 | 尝试一下 |
Convert from Yards to Inches | in=yd*36 | 尝试一下 |
Convert from Yards to cm | cm=yd/0.010936 | 尝试一下 |
Convert from Yards to Kilometers | km=yd/1093.6 | 尝试一下 |
Convert from Yards to Miles | mi=yd*0.00056818 | 尝试一下 |
下表显示了如何将公里转换为其他长度测量值:
Description | Formula | Example |
---|---|---|
Convert from Kilometers to Feet | ft=km*3280.8 | 尝试一下 |
Convert from Kilometers to Meters | m=km*1000 | 尝试一下 |
Convert from Kilometers to Inches | in=km*39370 | 尝试一下 |
Convert from Kilometers to cm | cm=km*100000 | 尝试一下 |
Convert from Kilometers to Yards | mi=km*1093.6 | 尝试一下 |
Convert from Kilometers to Miles | mi=km*0.62137 | 尝试一下 |
下表显示了如何从英里转换为其他长度测量值:
Description | Formula | Example |
---|---|---|
Convert from Miles to Feet | ft=mi*5280 | 尝试一下 |
Convert from Miles to Meters | m=mi/0.00062137 | 尝试一下 |
Convert from Miles to Inches | in=mi*63360 | 尝试一下 |
Convert from Miles to cm | cm=mi/0.0000062137 | 尝试一下 |
Convert from Miles to Yards | yd=mi*1760 | 尝试一下 |
Convert from Miles to Kilometers | km=mi/0.62137 | 尝试一下 |
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!