zoukankan      html  css  js  c++  java
  • js 自定义事件

    <!DOCTYPE html>
    <html>
    <head lang="zh-CN">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1"/>
    <title></title>
    <style>
      .button {
           200px;
          height: 200px;
          background-color: antiquewhite;
          margin: 20px;
          text-align: center;
          line-height: 200px;
      }
    </style>
    </head>
    <body>
    <div class="button">Button</div>
    <script>
      "use strict";
      var btn = document.querySelector('.button');
      var ev = new Event('test', {
          bubbles: 'true',
          cancelable: 'true'
      });
      btn.addEventListener('test', function (event) {
          console.log(event.bubbles);
          console.log(event.cancelable);
          console.log(event.detail);
      }, false);
      btn.dispatchEvent(ev);
    </script>
    </body>
    </html>
    <!DOCTYPE html>
    <html>
    <head lang="zh-CN">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1"/>
    <title></title>
    <style>
      .button {
           200px;
          height: 200px;
          background-color: antiquewhite;
          margin: 20px;
          text-align: center;
          line-height: 200px;
      }
    </style>
    </head>
    <body>
    <div class="button">Button</div>
    
    <script>
      "use strict";
      var btn = document.querySelector('.button');
    
      var ev = new CustomEvent('test', {
          bubbles: 'true',
          cancelable: 'true',
          detail: 'tcstory'
      });
      btn.addEventListener('test', function (event) {
          console.log(event.bubbles);
          console.log(event.cancelable);
          console.log(event.detail);
      }, false);
      btn.dispatchEvent(ev);
    </script>
    </body>
    </html>
  • 相关阅读:
    c#的Marshal
    爬虫之requests详解
    爬取抖音视频
    爬取拉钩网
    爬虫自动登陆GitHub
    爬取博客园博客
    爬取煎蛋网文章
    爬取抽屉热搜榜文章
    准备
    爬虫示例
  • 原文地址:https://www.cnblogs.com/gaocong/p/7844634.html
Copyright © 2011-2022 走看看