欢迎来到代码驿站!

JavaScript代码

当前位置:首页 > 网页前端 > JavaScript代码

js实现页面图片消除效果

时间:2021-04-09 08:59:53|栏目:JavaScript代码|点击:

本文实例为大家分享了js实现页面图片消除的具体代码,供大家参考,具体内容如下

前两天测试的时候发现自己对js还不是太熟悉,所以今天上传的了这篇文章,重新写了一下js模块里面的东西。

核心还是这一部分:

i = 0
last = null
function clickDisappear(obj){
 if(i==0 && last==null){
   i =1
   last=obj
 }
 else{
 if(obj != last){
  if(obj.src == last.src){
  obj.style.display='none'
  last.style.display='none'
  }
  i = 0
  last = null
 }
}
}

全部代码:

<!DOCTYPE html>
<html>
 <head>
 <meta charset="UTF-8">
 <title></title>
 <style type="text/css">
  img{
  margin: 9px;
  float: left;
  width: 32px;
  height: 32px;
  }
 </style>
 <script type="text/javascript">
  // DOM模型:文档对象模型
  i = 0
  last = null
  function clickDisappear(obj){
  if(i == 0 && last == null){
   last = obj
   i = 1
  }else{
   if(obj != last){
   if(obj.src == last.src){
    obj.style.display = 'none'
    last.style.display = 'none'
   }
   i = 0
   last = null
   }
  }
  }
 </script>
 </head>
 <body >
 <table cellpadding="0" cellspacing="1" style="border:solid 1px red;background-color: red;" >
  <caption>图片消除</caption>
  <thead>
  <tr valign="middle" align="center" >
   <!--<th colspan="2">1</th>-->
   <th>1</th>
   <th>2</th>
   <th>3</th>
   <th>4</th>
   <th>5</th>
   <th>6</th>
   <th>7</th>
   <th>8</th>
   <th>9</th>
   <th>10</th>
  </tr>
  </thead>
  <tbody style="background-color: royalblue;" >
  <tr valign="middle" align="center" >
   <td><img src="img/bg-0092.gif" onclick="clickDisappear(this)"></td>
   <td><img src="img/bg-0704.gif" onclick="clickDisappear(this)"></td>
   <td><img src="img/bg-0704.gif" onclick="clickDisappear(this)"</td>
   <td><img src="img/bg-0884.gif" onclick="clickDisappear(this)"</td>
   <td><img src="img/bg-0884.gif" onclick="clickDisappear(this)"</td>
   <td><img src="img/bg-0092.gif" onclick="clickDisappear(this)"</td>
   <td><img src="img/bg-0704.gif" onclick="clickDisappear(this)"</td>
   <td><img src="img/bg-0884.gif" onclick="clickDisappear(this)"</td>
   <td><img src="img/bg-0884.gif" onclick="clickDisappear(this)"</td>
   <td><img src="img/bg-0092.gif" onclick="clickDisappear(this)"</td>
  </tr>
  </tbody>
  <tfoot></tfoot>
 </table>
 </body>
</html>

上一篇:IE7中javascript操作CheckBox的checked=true不打勾的解决方法

栏    目:JavaScript代码

下一篇:Openlayers学习之加载鹰眼控件

本文标题:js实现页面图片消除效果

本文地址:http://www.codeinn.net/misctech/97510.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有