这有何难?给你一个最简单的版本你自己去完善吧。
<head><script type="text/javascript">
<!--
function calc(){
var num1=+document.getElementById("num1").value
var s = document.getElementById("s").value
var num2 = +document.getElementById("num2").value
if(s=="+"){
alert(num1+num2)
} else if(s=="-"){
alert(num1-num2)
} else if(s=="*"){
alert(num1*num2)
} else if(s=="/"){
alert(num1/num2)
}
}
//-->
</script>
</head>
<body>
<input type="text" name="" id="num1"><input type="text" name=""id="s"><input type="text" name=""id="num2"><input type="button" value="Calc" onclick="calc()">
</body>
</html>
<!--表单计算Start--><input id="htjia"/><br/>
<input id="ssjia"/><br/>
<input id="sdjia"/><br/>
<input id="sfl"/><br/>
<br/>
<input id="hje"/><br/>
<input id="hjlu"/><br/>
<input id="jbf"/><br/>
<input id="xyf"/><br/>
<input id="ysf"/><br/>
<br/>
<input type="button" value="计算" onclick="calc()"/><br/>
<script>
function calc(){
var jbf
var htjia = document.getElementById("htjia").value
var ssjia = document.getElementById("ssjia").value
var sdjia = document.getElementById("sdjia").value
var sfl = document.getElementById("sfl").value
if(htjia==""){
alert("合同价为空!请重新输入")
return false
}
if(ssjia==""){
alert("送审价为空!请重新输入")
return false
}
if(sdjia==""){
alert("审定价为空!请重新输入")
return false
}
//计算核减额
hje = sdjia - ssjia
//计算核减率
hjlu = hje / ssjia * 100
//计算基本费
if(ssjia <= 2000000){
jbf = ssjia * 0.006 * sfl
} else if (ssjia > 2000000 && ssjia <= 5000000){
jbf = (2000000 * 0.006 + (ssjia - 2000000) * 0.005) * sfl
} else if (ssjia > 5000000 && ssjia <= 10000000){
jbf = (2000000 * 0.006 + 3000000 * 0.005 + (ssjia - 5000000) * 0.0045) * sfl
} else if (ssjia > 10000000 && ssjia <= 30000000){
jbf = (2000000 * 0.006 + 3000000 * 0.005 + 5000000 * 0.0045 + (ssjia - 20000000) * 0.004) * sfl
} else if (ssjia > 30000000 && ssjia <= 50000000){
jbf = (2000000 * 0.006 + 3000000 * 0.005 + 5000000 * 0.0045 + 20000000 * 0.004 + (ssjia - 30000000) * 0.0035) * sfl
} else if (ssjia > 50000000){
jbf = (2000000 * 0.006 + 3000000 * 0.005 + 5000000 * 0.0045 + 20000000 * 0.004 + 20000000 * 0.0035 + (ssjia - 50000000) * 0.003) * sfl
}
// 计算效益费
if (hjlu > 5) {
xyf = ssjia * (hjlu - 0.05) * 0.025
}else{
xyf = 0
}
//计算应收费
ysf = jbf + xyf
//把算出来的值填到相应的表单中
document.getElementById("hje").value = hje
document.getElementById("hjlu").value = hjlu
document.getElementById("jbf").value = jbf
document.getElementById("xyf").value = xyf
document.getElementById("ysf").value = ysf
}
</script>
<!--表单计算End-->
代码如下:
<!DOCTYPE html><html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>demo1</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script type="text/javascript">
function calc() {
var n = parseInt(document.getElementById("number").value)
if (!n || n < 1) {
alert('请输入一个大于0的数字。')
return
}
var result = 1
for (var i = 1 i <= n i++) {
result *= i
}
document.getElementById("result").innerText = n +'! = ' + result
}
</script>
</head>
<body>
<input id="number" type="text" /><button onclick="calc()">计算</button>
<br />
<div id="result"></div>
</body>
</html>
运行结果: