本文介绍了将总函数添加到html计算器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Tip Calculator Application</title>
<script>
function tipCalculate(slider,bill,total){
var tip = document.getElementById('tip');
var slideval = document.getElementById('slideval');
var bill = document.getElementById(bill).value;
var prcnt = slider * .01;
var total = tip + bill;
total.innerHTML = " $ " +(tip + bill).toFixed(2);
tip.innerHTML = " $ "+(bill * prcnt).toFixed(2);
slideval.innerHTML = slider+"%";
}
</script>
</head>
<body>
<h2>Tip Calculator</h2>
Amount: $
<input type="text" id="bill"><br>
Tip Percentage:
<input type="range" min="0" max="100" value="0" step="1" onchange="tipCalculate(this.value,'bill')" style="width:300px;">
<span id="slideval">0%</span>
<p>Tip =<span id="tip"></span></p>
<p>Total =<span id="total"></span></p>
</body>
</html>
推荐答案
这篇关于将总函数添加到html计算器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!