问题
当在js文件中写好了如下代码:
var button = document.getElementById('btn');
button.addEventListener("click",function(){alert("hhh");
});
为按钮绑定了一个事件,点击按钮时没反应
解决
虽然我们写好了函数,但是它并没有执行
应该让它在页面加载的时候就执行
window.onload = function(){var button = document.getElementById('btn');button.addEventListener("click",function(){alert("hhh");});
}