Mar*_*ark 3 html javascript css parsefloat tofixed
我有我的代码并且它正在工作,但我正在尝试将 parseFloat 选项和“toFixed()”添加到小数点后两位。我对这两行代码应该放在哪里感到困惑。我创建了一个单位转换网站,可以将用户输入的英寸数转换为英尺。
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<center><title>Unit Coversion Table</title><center>
</head>
<body>
<div id="question">
<h2>Unit Convertor</h2>
<p>Enter a Quanity of Inches: <input id="userinches" type="number" /> </p>
</div> <!-- End of question div section -->
<div id="conversion">
<script>
function feet() {
var userinches = document.getElementById('userinches').value;
doOuput('The answer is ', userinches * 0.0833);
}
function doOuput(val, unit) {
document.getElementById('results').innerHTML = val + unit;
}
</script>
</div> <!-- End of conversion div section -->
<div="buttons">
<button type="button" id="buttonft" onclick="feet();">Feet</button>
</div> <!-- End of buttons div section -->
<div id="results"></div> <!-- End of results div section -->
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
小智 5
您可以将其添加到 foot() 函数中,在该函数中获取输入值并将其转换为英尺:
function feet() {
var userinches = document.getElementById('userinches').value;
var feetValue = parseFloat(userinches * 0.0833).toFixed(2);
doOuput('The answer is ', feetValue);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9178 次 |
| 最近记录: |