<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <script> function figure1(){ var figure = money.value; var wushi = Math.floor(figure/50); var ershi = Math.floor(figure%50/20); var shiyuan = Math.floor(figure%50%20/10); var wuyuan = Math.floor(figure%50%20%10/5); var yiyuan = Math.floor(figure - wushi*50 - ershi*20 - shiyuan*10 - wuyuan*5); //alert(figure); show.innerHTML = figure+"="+"50:"+wushi+" 20:"+ershi+" 10:"+shiyuan+" 5:"+wuyuan+" 1:"+yiyuan; } </script> </head> <body> <form action=""> 找零金额:<input type="text" name="money" id="money"><br> <input type="button" value="计算金额" onclick="figure1()"> </form> <p id="show"></p> </body>
javascript 小例子(待补充),布布扣,bubuko.com
原文地址:http://blog.csdn.net/qilixiang012/article/details/27580173