Eventtoをクリックして
11777 ワード
Javascriptの使い方
onclick
, 閉じるこの動画はお気に入りから削除されています.onclick
:<element onclick="function()">Clique here</element>
<button onclick="function()">Clique here</button>
注意: Oアトビュートonclick
JavaScriptを作成します.Oのヴァルqueエレは、楽しい部分を得られます.エムJavaScriptのデモンストレーションは、UMAの楽しい結果は、シャンプー-ペロノームe emのsegua adgionamosは、nnes es nteesとしてapのoを識別します.
function() {
// código
}
EASE projeto tem como objetivo mudar a cor do background da da p gina ao clicar no bot o o o .
vamos ver cada parte do c go digo e entender como funcionaを使います.
ADO COM O NOSSO C SEND DIGO HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>🎨Background Changer🎨</title>
<link rel="stylesheet" href="style.css" />
<script src="script.js" defer></script>
</head>
<body>
<button id="btn">🌈Change Me🌈</button>
</body>
</html>
デポイスの定性@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@200;400;600&display=swap");
* {
box-sizing: border-box;
}
body {
display: flex;
align-items: center;
justify-content: center;
font-family: "Poppins", sans-serif;
margin: 0;
min-height: 100vh;
}
button {
background-color: rebeccapurple;
color: white;
padding: 1rem;
font-family: inherit;
font-size: 1.2rem;
box-shadow: 2px 2px 6px rgba(0, 0, 0, 0.2);
border-radius: 5px;
border: none;
transition: transform 0.1s linear;
}
button:focus {
outline: none;
}
button:active {
box-shadow: 0;
transform: translate(2px, 2px);
}
結果アゴラiRemos adicionar o nossoは、onclickをonclickします.
const btn = document.getElementById('btn');
btn.addEventListener('click', () =>{
document.body.style.background = randomBg();
});
function randomBg() {
return `hsl(${Math.floor(Math.random()
* 360)}, 100%, 50%)`;
}
Primeiramente iRemos adicionarは楽しいbtn
onde serは、passada naタグHTML e irbtn
que serは、o nossoボットです.アオOcorrer o Eventoデクリーク
addEventListener
楽しいIRは、executarを楽しみますramdomBg
Re ir Torre Rtornnar Muma Cor Aleat‐de RiaOBS : O
addEventListener()
サーブパラEperarアムEvento que ser Aciionado Eアッシマーシャマー楽しいrefhttps://developer.mozilla.org/pt-BR/docs/Web/API/EventTarget/addEventListener
結果
エステEpico Mostra como vocは、o o id o o idを詠唱します
btn.addEventListener('click', (e) =>{
document.body.style.background = randomBg();
console.log(e.target.id)
});
<研究ノート>パキスタンの異端についてbtn
onclick != onClick
Seja mais em :https://pt-br.reactjs.org/docs/handling-events.html Veja mais sobre :
Reference
この問題について(Eventtoをクリックして), 我々は、より多くの情報をここで見つけました https://dev.to/beatrizoliveira/evento-de-click-no-javascript-18hgテキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol