Estoy haciendo una ejercicio de simulación básica de cajero。
执行代码时出现以下错误,我找不到错误。
无法读取属性“addEventListener”
非常感谢您的指导,谢谢!
js:
class billete{
constructor(v,c){
this.valor=v;
this.cantidad=c;
}
}
function entregarDinero()
{
for(var bi of caja)
{
console.log(bi);
}
}
var caja=[];
var entregado=[];
caja.push(new billete(50,3));
caja.push(new billete(20,2));
caja.push(new billete(10,2));
var dinero=210;
var div=0;
var papeles=0;
var b=document.getElementById("extraer");
b.addEventListener("click", entregarDinero);
HTML
<!DOCTYPE html>
<html>
<head>
<title>Cajero</title>
</head>
<body>
<h1>Mi primer cajero!</h1>
<p> wow! :O </p>
<img src="cajero.webp">
</br>
<script src="cajero.js"></script>
<input type="number" id="dinero">
<input type="button" value="Extraer" id="extraer" />
</body>
</html>
我已经测试了您的代码,它功能齐全,您可能拥有的唯一细节是您编写 JS 的位置;我告诉你你的代码应该有这个顺序
适应症
功能代码