0

因此,我找到了一个脚本,可以在单击我选择的另一个元素时很好地显示隐藏的 div。但是,我希望这更像是一个切换。谁能帮我吗?我已经尝试尽我所能调整脚本,但 jQuery 不是我的强项。

<script type="text/javascript">
    (function($){
    document.documentElement.className += " js"; // Add js class to the HTML element
    $(function(){
      var $containers = $("#repaircontent").hide();

      jQuery(document).ready(function(){
       /* Show the HTML page only after the js and css are completely loaded */
       delayShow();
      });

      function delayShow() {
        var secs = 1000;
            setTimeout('jQuery("#repaircontent").css("visibility","visible");', secs);
      }

      $('#repairtab').each(function(i,el){
        var idx = i;
        $(this).click(function(e){
          var $target = $containers.filter(':eq(' + idx + ')');
          $target.not(':visible').fadeIn();
          e.preventDefault();

        })
      })
    })
    })(jQuery);
</script>
4

2 回答 2

3

你试过jquery的切换吗?http://api.jquery.com/toggle/

于 2013-03-08T14:46:17.650 回答
1

只需用切换替换淡入...

      $('#repairtab').each(function(i,el){
    var idx = i;
    $(this).click(function(e){
      var $target = $containers.filter(':eq(' + idx + ')');
      $target.toggle();
      e.preventDefault();

    })
  })
})
})(jQuery);
于 2013-03-08T14:57:26.327 回答