<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>华氏转摄氏</title>
<script type="text/javascript" src="../js/jquery-1.8.3.min.js"></script>
<script>
$(document).ready(function(){
//华氏-->摄氏
$("#ftoc").click(function(){
var temp = $("#fahrenheit").val()
if(temp==''){
alert("请输入华氏湿度!");
}
if(temp){
var celsius = (parseFloat((temp-32)*(5/9))).toFixed(2);
$("#c").val(celsius);
}
});
//摄氏-->华氏
$("#ctof").click(function(){
var temp = $("#cel").val()
if(temp==''){
alert("请输入摄氏温度!");
}
if(temp){
var fahs = (parseFloat((parseFloat(temp)+parseFloat(32))*1.8)).toFixed(2);
$("#fah").val(fahs);
}
});
});
</script>
</head>
<body>
<h3></h3>
<input type="text" name="fahrenheit" id="fahrenheit" maxlength="10"
class="form-txt" />
<input type="button" id="ftoc" value="华氏-->摄氏" />
<input disable="disable" type="text" name="c" id="c" maxlength="10"
readonly value="" class="form-txt" />
<br><br>
<1--摄氏温度转华氏温度-->
<input type="text" name="cel" id="cel" maxlength="10"
class="form-txt" />
<input type="button" id="ctof" value="摄氏-->华氏" />
<input disable="disable" type="text" name="fah" id="fah" maxlength="10"
readonly value="" class="form-txt" />
</body>
</html>
Js中parseFloat()精度问题
最新推荐文章于 2025-06-11 09:00:12 发布