-1

我正在调用以下代码将 html 加载到 div 中。

        $('#strap').click(function(e) {
        e.preventDefault();
        $('#collection_content').load('collection_sub.html');

    });

我称之为让它消失

$('#collection_content').hide();

但是当我尝试再次加载相同的 html 文件时,它没有显示任何内容.. 是因为它被隐藏了吗?我应该如何让它再次出现?目前,'collection_sub.html' 是静态的,但它将被替换为 php 动态页面,所以我想重新加载它.. 有什么办法吗?

谢谢。

4

2 回答 2

1

要让它再次出现,只需调用.show()

$('#collection_content').show().load('collection_sub.html');

如果元素已经可见,.show()则不会有任何效果。

于 2013-05-19T17:42:50.640 回答
0

.load. hide.show

在这里你要点击 id = strap 然后它会加载一个collection_sub.html页面到div是collection_content.so如果你想在加载后隐藏你需要像这样使用它。如果你想显示它当再次单击#strap 时,您想像下面这样使用它

       $('#strap').click(function(e) {
            e.preventDefault();
            $('#collection_content').load('collection_sub.html',function(){
    $('#collection_content').hide();

     $('#strap').click(function(e) {

    $('#collection_content').show();

      });

  });

});
于 2013-05-19T17:50:15.390 回答