且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

点击容器中的内容,然后将内容加载到Jquery中

更新时间:2023-12-02 18:49:58

<button id="showHideTopContent">Show Hide Content</button>

<div id="container">
    <div id="topContent" style="display:none;">
        This is top content
        <hr />
    </div>
    <div id="topContent" style="display:none;">
        This is bottom content.
    </div>        
</div>

<script type="text/javascript">
    $(function() {
        $("#showHideTopContent").click(toggleTopContent);
    });

    function toggleTopContent() {
      var topContent = $("#topContent");
      var bottomContent = $("#bottomContent");

      if(!topContent.is(":hidden")) {
        topContent.hide();
        bottomContent.slideUp("slow");
      } else {
        // if you want the content to come from AJAX or so do it here
        //       ....
        //   If you do so, the topContent div should remain there, but empty.

        $("#topContent").slideDown("slow");
      }
    }
</script>