如何刷新特定的div内容与淡入&淡出

时间:2017-06-23 12:56:03

标签: javascript php jquery html ajax

如何使用淡入淡出来刷新特定的div内容淡出,我是这样创造的。当我点击按钮没有发生任何事情。
JavaScript的

$('#btn_click').click(function(){
  $('#postinganrefresh').fadeIn(1000);
  setTimeout(function(){
    $('#postinganrefresh').fadeOut(1000, function(){
      location.reload(true);
    });
  });
});

按钮单击

<a style="float: right;" class="btn btn-default" id="btn_click">
  <i class="fa fa-refresh"></i> Refresh
</a>

要刷新的特定div

<div class="container" id="postinganrefresh">
  mycontent table
</div>

2 个答案:

答案 0 :(得分:1)

您正在使用jQuery API(http://api.jquery.com/fadein/),但您应该包含jQuery。

<script src="http://code.jquery.com/jquery-latest.min.js"
    type="text/javascript"></script>

看到这个小提琴:https://jsfiddle.net/6nuopwau/

答案 1 :(得分:0)

使用location.reload(true);重新加载孔页。

你让setTimeout(没有时间出发了。写下来setTimeout(function(){ ... },2000);

如果您只想重新加载div内容,请查看jQuery函数$.ajax。 像:

$('#postinganrefresh').fadeOut(1000, function(){
 var t=$(this);
 $.ajax({type:"POST",url:window.location.href, data:{'somePostData':'andTheValue','post2':'value2' }}).always(function(e){
  t.html(e);
 });
});
相关问题