当在之后放置一个函数时,“click”事件不会发生:
<pre>
<body>
<section class="page">
<label for="name">Nome: </label>
<input type="text" name="nome">
<input type="button" value="Adicionar na lista">
</section>
<script>
var autores = [{nome:'CCarlos'},{nome:'Daniel'}];
var botao = document.querySelector('input[type=button]');
botao.addEventListener('click',aviso);
imprimir();
function aviso(){
alert('aasf');
}
function imprimir(){
var pagina = document.querySelector('.page');
for(i in autores){
enter code herepagina.innerHTML += `<p>${autores[i].nome}</p>`;
}
}
</script>
</body>
当我删除时,我工作得很好,不知道为什么会发生这种情况
慕姐8265434
红糖糍粑
相关分类