Javascript复选框切换div隐藏显示

时间:2015-04-29 13:33:19

标签: javascript html css checkbox

我希望在

时有一个复选框(足球)

未选中:

  • 显示一个DIV(FootballChoice),其中包含用鼠标悬停更改的复选框的标签图像

经过:

  • 隐藏DIV(FootballChoice)
  • 显示隐藏的DIV(FootballChecked),其中包含备用标签图像
  • 显示另一个隐藏的DIV(FootballTeams)。

再次取消选中时,需要返回原始状态。

或者,如果有人知道如何在检查时将标签图像更改为与鼠标悬停元素中指定的标签图像相同,那么这也是一个有用的替代品吗?

提前谢谢。

<script type="text/javascript" src="http://code.jquery.com/jquery.js"></script>
<script type="text/javascript">
  
  $(document).ready(function(){
    $('input[type="checkbox"]').click(function(){
      
      if($(this).attr("value")=="FootballTeams"){
        $(".FootballTeams").toggle();
        $(".FootballChecked").toggle();
        $(".FootballChoice").toggle();
        
      }
    });
  });

</script>
.FootballChecked {
  display: none;
}

.FootballChoice {
  display: show;
}

.sport {
  display: none; 
  border: 1px dashed #FF3333; 
  margin: 10px; 
  padding: 10px; 
  background: #003366;
}
<input id="Football" type="checkbox" value="FootballTeams">

<div class="FootballChoice">
  <label for="Football" class="FootballChoice">
    <img src="http://web.static.nowtv.com/email-marketing/assets/structure/SPORTSPREF_FOOTBALL_100x130.png" onmouseover="this.src='http://web.static.nowtv.com/email-marketing/assets/structure/SPORTSPREF_FOOTBALL_NAME_100x130.png';"                  onmouseout="this.src='http://web.static.nowtv.com/email-marketing/assets/structure/SPORTSPREF_FOOTBALL_100x130.png';" alt="Football" title="Football">
  </label>
</div>
          
<div class="FootballChecked">
  <label for="Football">
    <img src="http://web.static.nowtv.com/email-marketing/assets/structure/SPORTSPREF_FOOTBALL_NAME_100x130.png" alt="Football" title="Football">
  </label>
</div>

<div class="sport FootballTeams">
  Football Teams here
</div>

0 个答案:

没有答案