<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<input type="text">
<input type="button" value="请按">
</body>‘
<script>
var val = document.querySelectorAll("input");
console.log(val);
val[1].onclick = function(){
var money = val[0].value;
console.log(money);
//想要张数少,就要面值大的尽可能多
//先计算最多有几张20张
var twenty = Math.floor(money /20);
// twenty = parseInt(twenty);
console.log(twenty);
alert("20元面值有"+twenty+"张");
var ten = Math.floor(money%20/10);
// ten = parseInt(twenty);
console.log(ten);
alert("10元面值有"+ten+"张");
var five = Math.floor(money%10/5);
// five = parseInt(five);
console.log(five);
alert("5元面值有"+five+"张");
var one = Math.floor(money%5);
// one = parseInt(one);
console.log(one);
alert("1元面值有"+one+"张");
}
</script>
</html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<input type="text">
<input type="button" value="请按">
</body>‘
<script>
var val = document.querySelectorAll("input");
console.log(val);
val[1].onclick = function(){
var money = val[0].value;
console.log(money);
//想要张数少,就要面值大的尽可能多
//先计算最多有几张20张
var twenty = Math.floor(money /20);
// twenty = parseInt(twenty);
console.log(twenty);
alert("20元面值有"+twenty+"张");
var ten = Math.floor(money%20/10);
// ten = parseInt(twenty);
console.log(ten);
alert("10元面值有"+ten+"张");
var five = Math.floor(money%10/5);
// five = parseInt(five);
console.log(five);
alert("5元面值有"+five+"张");
var one = Math.floor(money%5);
// one = parseInt(one);
console.log(one);
alert("1元面值有"+one+"张");
}
</script>
</html>