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.

  • 相关阅读:
    css3新特性
    线程间通信的三种方法
    硬件相关知识
    time.h
    ldr指令总结
    你不知道的100个小秘密
    ARM学习日记
    C中位域的使用
    《编程之美》第2刷勘误
    排序2
  • 原文地址:https://www.cnblogs.com/hephec/p/4601142.html
Copyright © 2011-2022 走看看