码迷,mamicode.com
首页 > 其他好文 > 详细

W3C 事件切换 颜色变化

时间:2017-09-02 18:01:39      阅读:98      评论:0      收藏:0      [点我收藏+]

标签:span   link   type   listen   false   fun   oct   javascrip   char   

颜色变化代码:

HTML:

 

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" type="text/css"  href="web6.css">
    <script type="text/javascript" src="web6.js"></script>
    <style type="text/css">
        .red {
            width:100px;
            height:100px;
            background: red;
        }
        .blue{
            width:100px;
            height:100px;
            background: blue;
        }
    </style>
</head>
<body>
<div id="box" class="red">测试zhong</div>
</body>
</html>

 

 JS 

 

window.addEventListener(‘load‘,function(){
    var box=document.getElementById(‘box‘);
    box.addEventListener(‘click‘,toBlue,false);
},false);
function toRed() {
   this.className=‘red‘;
   this.removeEventListener(‘click‘,toRed,false);

   this.addEventListener(‘click‘,toBlue,false);
}
function toBlue() {
  this.className=‘blue‘;
    this.removeEventListener(‘click‘,toBlue,false);
  this.addEventListener(‘click‘,toRed,false);
}

 效果:

 技术分享

 

 

 16:04:28   2017-09-02 

W3C 事件切换 颜色变化

标签:span   link   type   listen   false   fun   oct   javascrip   char   

原文地址:http://www.cnblogs.com/guangzhou11/p/7466932.html

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