码迷,mamicode.com
首页 > Web开发 > 详细

js 自定义事件

时间:2017-11-16 15:52:39      阅读:232      评论:0      收藏:0      [点我收藏+]

标签:use   自定义   lin   isp   false   func   script   listener   cti   

<!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 {
      width: 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 {
      width: 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>

 

js 自定义事件

标签:use   自定义   lin   isp   false   func   script   listener   cti   

原文地址:http://www.cnblogs.com/gaocong/p/7844634.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!