zoukankan      html  css  js  c++  java
  • 104.什么是事件

    事件分为两部分:

      1.行为本身:浏览器天生就赋予其的行为 onClick,onmouseover(onmouserenter),onmouseout(onmouseleave),onmousemove,onmousedown,onmouseup,onmousewheel(鼠标滚轮滚动行为),onscroll(滚动条滚动行为),onresize(window.onresize浏览器窗口大小改变事件),onload,onunload(浏览器关闭的时候),onfocus(文本框获取焦点的行为),onblur(文本框失去焦点),onkeydown,onkeyup(键盘的按下和抬起 行为)...

      哪怕没有给上述的行为绑定方法,事件也是存在的,当我们点击这个盒子的时候同样会触发它的onClick行为,只是什么事情都没做而已

      2.事件绑定:给元素的某一个行为绑定方法

      方式一:DMO 0级事件绑定

      oDiv.oncick = function () {

        // 当我们触发oDiv的click行为的时候,会把绑定的这个函数执行

      }

      onclick这个行为定义在当前元素的私有属性上

      方式二:DMO2级事件绑定

      oDiv.addEventListener("click",function(){

        console.log("ok!")

      },false);

      addEventListener这个属性是定义在当前元素所属eventTarget这个类的原型上的

      

  • 相关阅读:
    0593. Valid Square (M)
    0832. Flipping an Image (E)
    1026. Maximum Difference Between Node and Ancestor (M)
    0563. Binary Tree Tilt (E)
    0445. Add Two Numbers II (M)
    1283. Find the Smallest Divisor Given a Threshold (M)
    C Primer Plus note9
    C Primer Plus note8
    C Primer Plus note7
    C Primer Plus note6
  • 原文地址:https://www.cnblogs.com/z-dl/p/8990274.html
Copyright © 2011-2022 走看看