jQuery隐藏并显示带有加号和减号图标的切换div

前端之家收集整理的这篇文章主要介绍了jQuery隐藏并显示带有加号和减号图标的切换div前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有代码为展示工作,并隐藏div.当显示和隐藏活动时,我将如何添加两个不同的图标作为精灵图像?

例如:显示我的图标,然后是一个隐藏我的图标.

这是代码,我有:
http://jsfiddle.net/BLkpG/

  1. $(document).ready(function(){
  2. $(".slidingDiv").hide();
  3. $(".show_hide").show();
  4.  
  5. $('.show_hide').click(function(){
  6. $(".slidingDiv").slideToggle();
  7. });
  8. });

切换到或 – 时,需要将图像更改为上述内容.

谢谢

解决方法

尝试这样的东西

jQuery的

  1. $(document).ready(function(){
  2.  
  3. $(".slidingDiv").hide();
  4. $(".show_hide").show();
  5.  
  6. $('.show_hide').toggle(function(){
  7. $("#plus").text("-");
  8. $(".slidingDiv").slideDown();
  9.  
  10. },function(){
  11. $("#plus").text("+");
  12. $(".slidingDiv").slideUp();
  13. });
  14.  
  15. });

HTML

  1. <a href="#" class="show_hide" id="plus">+</a>
  2.  
  3. <div class="slidingDiv" style="display: block;">
  4. Check out the updated jQuery plugin for doing this: <a href="http://papermashup.com/jquery-show-hide-plugin/" class="show_hide" target="_blank" style="display: inline;">jQuery Show / Hide Plugin</a>
  5. </div>

CSS

  1. .show_hide {
  2. display:none;
  3. }
  4. .a{
  5. font: 2em Arial;
  6. text-decoration: none
  7. }

DEMO

在这里查看本教程http://www.webstutorial.com/simple-jquery-toggle-tutorial-css-jquery-slide-toggle/jquery

DEMO

猜你在找的jQuery相关文章