js计算油耗代码怎么写,js实现油耗计算的方法教程如下:
1.输入上次加满油后行驶的公里数
2.输入本次油箱加满公升数
3.输入当日油价
计算结果:计算出每公里油耗和每公里需要多少钱
js实现代码:
function haoyoujisuan(f) {
var obaoil = f.a.value;
var obboil = f.b.value;
var obcoil = f.c.value;
if (obaoil.length == 0) {
alert('涓婃鍔犳弧娌瑰悗琛岄┒鐨勫叕閲屾暟涓嶈兘涓虹┖');
f.a.focus();
return false
}
if (obboil.length == 0) {
alert('鏈娌圭鍔犳弧鍏崌鏁颁笉鑳戒负绌�');
f.b.focus();
return false
}
if (obcoil.length == 0) {
alert('褰撴棩娌逛环涓嶅厑璁镐负绌哄€�');
f.c.focus();
return false
}
var rf = document.getElementById("jieguo");
rf.style.display = "";
var rs1 = document.getElementById("rs1");
var rs2 = document.getElementById("rs2");
var rs3 = document.getElementById("rs3");
rs1.innerHTML = (((Math.floor((Math.floor(obaoil / obaoil * 1000) * 1000))) / 1000) / 1000) + "鍏噷";
rs2.innerHTML = (((Math.floor((Math.floor(obboil / obaoil * 1000) * 1000))) / 1000) / 1000) + "鍏崌(绾︾瓑鍚�" + (((Math.floor((Math.floor(obboil / obaoil * 1000 * 1000) * 1000))) / 1000) / 1000) + "cc)鐨勬补";
rs3.innerHTML = (((Math.floor((Math.floor(obboil / obaoil * obcoil * 1000) * 1000))) / 1000) / 1000) + "鍏�";
return false
}
显示效果:百公里油耗计算器
参考文章:http://tishang.net/articles/1685452428.html