zoukankan      html  css  js  c++  java
  • 实现事件来回切换

    div

    1、新建一个层,点击层,希望层的背景色在蓝色和红色之间切换。




    <script type="text/javascript"> function addEVent(obj,type,fn){ var saved=null; //判断是否之前有事件,如果有,保存下来 if(typeof obj['on'+type]=='function'){ saved=obj['on'+type]; } //执行 obj['on'+type]=function(){ if(saved)saved(); fn.call(this); }; } addEVent(window,'load',function(){ var box=document.getElementById('box'); addEVent(box,'click',toBlue); }); function toBlue(){ this.className='blue'; addEVent(this,'click',toRed); } function toRed(){ this.className='red'; addEVent(this,'click',toBlue); } </script>
    <body>
    <div id="box" class="red">div</div>
    
    </body>
    
    <style type="text/css">
    .red{
    	100px;
    	height:100px;
    	background:red;
    	}
    
    .blue{
    	100px;
    	height:100px;
    	background:blue;
    	}
    </style>
    
  • 相关阅读:
    jQuery 全选-------左右移动select
    圆饼 折线图的 js
    折线图
    圆饼图
    el 表达式的if else
    list查询出来后存到map里
    spring Mvc 二级联动(3)
    Python之列表
    SAS 中的数据拼接
    Git 安装不是默认路径,生成密钥
  • 原文地址:https://www.cnblogs.com/jiangwenli/p/4891327.html
Copyright © 2011-2022 走看看