Eventtoをクリックして

11777 ワード

Javascriptの使い方

  • Normalmenteは、AOのVisitarmos Pは、ギアスのWeb、Executamosは、esは、atravのsデボットのes、リンクou ElemementosデUIリンクします.COMO SELECT ELMEMERTOS LINE VIS S EAVERO O atrav es s de eventos em JavaScript PIA Podermos Execuar Funcionalidade
  • イオス・イヴェルトスの作品集onclick , 閉じるこの動画はお気に入りから削除されています.
  • バージョンhttps://developer.mozilla.org/pt-BR/docs/Web/API/GlobalEventHandlers/onclick
  • シカタキBonclick :
  • <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
    }
    
  • onclickの例
  • Background-changer
    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 Ria
    OBS : OaddEventListener() サーブパラEperarアムEvento que ser Aciionado Eアッシマーシャマー楽しい
    refhttps://developer.mozilla.org/pt-BR/docs/Web/API/EventTarget/addEventListener
    結果
  • comoデバッガseus eventos comコンソール.ログ
  • つのVezes、Podemos Cererer Saber mais Informaは、es sosoe o evento、como qual elemento foi clicadoです.Nesseカモ、Preisisamos Passar um parは、メトロデEventoパラシュートで降下します.
    エステ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
  • Por queなし反応ononclick?
  • Bericamente a nomeaの遺言o de eventos emは、sのu usando camelcase ao inv es s de letras minfia . scasを反応させます.
    onclick != onClick
    
    Seja mais em :https://pt-br.reactjs.org/docs/handling-events.html
    Veja mais sobre :
  • https://www.freecodecamp.org/news/javascript-addeventlistener-example-code/
  • https://www.freecodecamp.org/portuguese/news/tutorial-sobre-button-onclick-em-html-e-evento-de-clique-em-javascript/#:~:text=O%20evento%20onclick%20executa%20determinada,tag%20de%20abertura%20do%20bot%C3%A3o
  • https://developer.mozilla.org/pt-BR/docs/Web/API/GlobalEventHandlers/onclick