我收到未捕获的类型错误:未捕获的类型错误:无法设置 null 的属性“onclick”
<!DOCTYPE html>
<html>
<head>
<title>dice app</title>
<script src="widget.js"></script>
</head>
<body>
<button id="button">Roll Dice</button>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
js代码:
var button = document.getElementById("button");
button.onclick = function() {// error
var print = dice.roll();
printNumber(print);
};
Run Code Online (Sandbox Code Playgroud)