Interatividade com JavaScript
Introduzido| English | Significado |
|---|---|
| DOM/dɒm/ | DOM |
| event/ɪˈvent/ | evento |
| function/ˈfʌŋkʃn/ | função |
A menu opens, but its button still says it is closed
- A visible panel and its accessibility state can disagree. A reliable interaction updates both the content and the control that describes it.
- Browser JavaScript responds to user actions. Do not put private credentials in client code; visitors can inspect and change what runs on their machines.
Find the parsed elements
- The DOM 文档对象模型 represents the document as nodes as HTML is parsed. Code can query an existing node and change its properties.
- A script running before its target is parsed may get
null. A deferred external script runs after parsing; a script at the end of the body can also work for elements already above it.
O que o DOM representa?
Dificuldade 1/5 · Moedas 100 + pequeno bônus na primeira conclusão hoje
Os nós tornam-se disponíveis conforme o documento é analisado; uma consulta não pode encontrar um alvo que ainda não foi analisado.
Register the response once
- An event 事件 records an action such as a click or form submission.
addEventListenerregisters a function 函数 to run when that event is dispatched. - Find the button and panel, register the listener, then update state on each click. Do not call the function while registering it if you mean to pass it as a handler.

Qual método registra um manipulador de eventos em um elemento?
Dificuldade 1/5 · Moedas 100 + pequeno bônus na primeira conclusão hoje
addEventListener registra um callback para um evento como clique.
Coloque as etapas para configurar esta interação em ordem.
Dificuldade 3/5 · Moedas 200 + pequeno bônus na primeira conclusão hoje
O registro precede a resposta ao evento; o manipulador é executado quando o evento é disparado.
Keep a usable fallback
- Save this as an HTML file. The links are initially visible; the toggle button appears only after its handler is ready.
- Click the button twice. Check that the panel and
aria-expandedchange together. The native button also responds to keyboard activation.
<!doctype html>
<html lang="en">
<head><meta charset="utf-8"><title>Club menu</title></head>
<body>
<button id="menu-button" type="button" hidden
aria-controls="menu-panel" aria-expanded="true">Menu</button>
<nav id="menu-panel" aria-label="Club">
<a href="#meeting">Meeting details</a>
</nav>
<main id="meeting"><h1>Meet Thursday in room 12</h1></main>
<script>
const button = document.querySelector('#menu-button');
const panel = document.querySelector('#menu-panel');
button.addEventListener('click', () => {
panel.hidden = !panel.hidden;
button.setAttribute('aria-expanded', String(!panel.hidden));
});
button.hidden = false;
</script>
</body>
</html>
Initially: links visible, expanded true. First click: links hidden, expanded false. Second click: links visible, expanded true. With JavaScript disabled, the original links remain visible.
No exemplo resolvido, o JavaScript está desativado. O que acontece com os links de navegação originais?
Dificuldade 1/5 · Moedas 100 + pequeno bônus na primeira conclusão hoje
Os links começam visíveis. O botão começa oculto, então a falha no aprimoramento não remove a navegação essencial.
Combine cada estado do painel com o estado correto do botão.
Dificuldade 2/5 · Moedas 140 + pequeno bônus na primeira conclusão hoje
aria-expanded descreve se a região controlada está expandida no momento.
Separate helpful checks from trusted checks
- Browser validation can give quick feedback, but the server must validate submitted values and permissions independently. A caller can bypass or alter browser code.
- Use
textContentto insert plain text rather than interpreting it as HTML. Check missing elements and errors before adding more features.
A click handler alone does not make a custom element keyboard accessible. Use the appropriate native control and verify focus and activation. Also check that your CSS does not override the panel's hidden state.
Um servidor deve validar valores submetidos mesmo se o navegador já os tiver verificado.
Dificuldade 1/5 · Moedas 100 + pequeno bônus na primeira conclusão hoje
Verdadeiro. Os chamadores podem contornar ou alterar o código do navegador, então o servidor deve verificar valores e permissões independentemente.
Trace two actions and a failure
- Record initial state and the state after two activations. Repeat using the keyboard, then check that essential navigation remains available without the script.
- Explain what runs in the browser and what still needs server checks. Test this local example without sending any real form data.
Parsed element → registered event handler → consistent state update. Preserve useful fallback content and keep trusted validation on the server.
O painel começa visível. O alternador é executado duas vezes. Qual é o estado final?
Dificuldade 1/5 · Moedas 100 + pequeno bônus na primeira conclusão hoje
O primeiro clique o oculta; o segundo o restaura. Ambos os estados devem permanecer consistentes.
Quais verificações pertencem a esta revisão de interação local? Selecione todas as que se aplicam.
Dificuldade 2/5 · Moedas 140 + pequeno bônus na primeira conclusão hoje
Teste operação, estado e fallback. O código do navegador não é um lugar seguro para credenciais privadas.