Created
December 30, 2013 08:00
-
-
Save jay16/8179141 to your computer and use it in GitHub Desktop.
感觉算法上有好多地方可以优化,暂放,以备忘
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div> | |
<input type="text" id="input_value" onkeydown="enterIn(event);" /> | |
<input type="button" value="计算" id="cal_btn" /> | |
</div> | |
<div> | |
结果:<span id="ret_value"></span> | |
</div> | |
<div> | |
公式:<span id="ret_cal"></span> | |
</div> | |
<script> | |
function calcuation(value) { | |
var tmp = ""; | |
var ret = 0; | |
if(value >1000 && value<=10000) { | |
ret = 0; | |
tmp = "0"; | |
} else if(value >10000 && value <= 100000) { | |
ret = (value-10000)*0.04+1000; | |
tmp = "("+value+"-10000)*0.04+1000" | |
} else if(value > 100000 && value <= 500000) { | |
ret = (value-100000)*0.035+90000*0.04+1000; | |
tmp = "("+value+"-100000)*0.035+90000*0.04+1000" | |
} else if(value > 500000 && value <= 1000000) { | |
ret = (value-500000)*0.03+400000*0.035+90000*0.04+1000; | |
tmp = "("+value+"-500000)*0.03+400000*0.035+90000*0.04+1000;" | |
} else if(value > 1000000 && value <= 5000000) { | |
ret = (value-1000000)*0.025+500000*0.03+400000*0.035+90000*0.04+1000; | |
tmp = "("+value+"-1000000)*0.025+500000*0.03+400000*0.035+90000*0.04+1000" | |
} else if(value > 5000000 && value <= 10000000) { | |
ret = (value-5000000)*0.02+4000000*0.025+500000*0.03+400000*0.035+90000*0.04+1000; | |
tmp = "("+value+"-5000000)*0.02+4000000*0.025+500000*0.03+400000*0.035+90000*0.04+1000" | |
} else if(value > 10000000 && value <= 50000000) { | |
ret = (value-10000000)*0.0175+5000000*0.02+4000000*0.025+500000*0.03+400000*0.035+90000*0.04+1000; | |
tmp = "("+value+"-10000000)*0.0175+5000000*0.02+4000000*0.025+500000*0.03+400000*0.035+90000*0.04+1000;" | |
} else if (value > 50000000) { | |
ret = (value - 50000000)*0.015 + 40000000*0.0175+5000000*0.02+4000000*0.025+500000*0.03+400000*0.035+90000*0.04+1000; | |
tmp = "("+value+"-50000000)*0.015 + 40000000*0.0175+5000000*0.02+4000000*0.025+500000*0.03+400000*0.035+90000*0.04+1000;" | |
} else { | |
alert("error num:"+value); | |
} | |
return [parseInt(ret),tmp] | |
} | |
//监视回车 | |
function enterIn(evt){ | |
var evt=evt?evt:(window.event?window.event:null);//兼容IE和FF | |
if (evt.keyCode==13) | |
calcuation_mm() | |
} | |
//按钮点击 | |
document.getElementById("cal_btn").onclick = function(){ calcuation_mm(); }; | |
//显示计算结果值 | |
function calcuation_mm() { | |
var value = parseInt(document.getElementById("input_value").value); | |
var ret = calcuation(value); | |
var ret_value = ret[0]; | |
var ret_cal = ret[1]; | |
document.getElementById("ret_value").innerHTML = ret_value; | |
document.getElementById("ret_cal").innerHTML = ret_cal; | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment