zoukankan      html  css  js  c++  java
  • Events

     

    To create real interactivity on a website, you need events — these are code structures that listen out for things happening to the browser, and then allow you to run code in response to those things. The most obvious example is the click event, which is fired by the browser when the mouse clicks on something. To demonstrate this, try entering the following into your console, then clicking on the current webpage:

    document.querySelector('html').onclick = function() {
        alert('Ouch! Stop poking me!');
    }
     
    

      

    There are many ways to attach an event to an element. Here we are selecting the HTML element and setting its onclick handler property equal to an anonymous (i.e. nameless) function that contains the code we want to run when the click event occurs.

    Note that

    document.querySelector('html').onclick = function() {};
    

      

     

    is equivalent to

    var myHTML = document.querySelector('html');
    myHTML.onclick = function() {};
    

      

     

    It's just shorter.

  • 相关阅读:
    test
    结构体内存对齐
    单链表(指针的指针应用)
    C语言实现线程池
    线程私有数据和pthread_once
    fcntl函数
    同构树
    动态规划经典题
    DP--方格取数问题
    动态规划的基本模型
  • 原文地址:https://www.cnblogs.com/hephec/p/4601142.html
Copyright © 2011-2022 走看看