我有以下代码。除了我希望最终的 tinstotal 变量四舍五入到最接近的 1(2.04 被四舍五入到 3 等)之外,效果很好
$(document).ready(function(){
// Animate logo
$('#Logo').hide().fadeIn(800);
// Calculation Scripts
// Square Metres
var output = $('#SquareMetres'),
tinoutput = $('#Tins'),
priceoutput = $('#Price');
$('input[type="text"]').keyup(function() {
var width = parseFloat( $('#width').val()),
height = parseFloat( $('#height').val()),
result = height * width / 10000,
finalresult = result.toFixed(2);
if (isNaN(result)) return;
output.text(finalresult);
// Tins
var tinmetres = 32.5,
tinprice = 18.23,
tinsresult = finalresult / tinmetres;
tinstotal = tinsresult.toFixed(2);
tinoutput.text(tinstotal);
var price = tinstotal * tinprice,
totalprice = price.toFixed(2);
priceoutput.text('£'+totalprice)
});
});
该脚本在底部附近的红色框中的http://andyholmes.me/sitewizard/index.html处于活动状态。希望各位大神帮忙,谢谢!