您的位置:首页 > Web前端 > JavaScript

<javascript>元素更新后不立即显示在页面上的问题

2016-04-29 19:20 627 查看
关于下面这段代码中更新#description元素内容不立即显示在页面上,而要等到整片js代码执行完才刷新页面的问题:

if(this.rabbit===true){
this.level=this.tempLevel;
$("#description p").remove();
$("#description").html("<p>嘭!</p>");
/*alert($("#description").text());*/
console.log($("#description").html());
this.sleep(1000);
this.rabbit=false;
$("#description p").remove();
$("#description").html("<p>一个胖子的力量...</p>");
/*alert($("#description").text());*/
console.log($("#description").html());
this.sleep(1000);
$(".play_cell.active").removeClass("active");
$(".play_cell.rabbit").removeClass("rabbit");
$("#description p").remove();
this.score += 500;
console.log(this.score);
this.e_playScore.html(this.score);
this.fullArr = [];
this.nextTetris();
return;
}


</pre><pre>


可以参照 js更新dom后的强制刷新问题通过调用setTimeout()函数来强制刷新dom,更改代码如下:

if(this.rabbit===true){
this.level=this.tempLevel;
$("#description p").remove();
$("#description").html("<p>嘭!</p>");
/*alert($("#description").text());*/
console.log($("#description").html());
setTimeout(this.forceRefresh_1(self),1000);
return;
}
forceRefresh_1:function(self1){
this.rabbit=false;
$("#description p").remove();
$("#description").html("<p>一个胖子的力量...</p>");
/*alert($("#description").text());*/
console.log($("#description").html());
setTimeout(self.forceRefresh_2(self1),1000);
return;
},
forceRefresh_2:function(self2){
$(".play_cell.active").removeClass("active");
$(".play_cell.rabbit").removeClass("rabbit");
$("#description p").remove();
this.score += 500;
console.log(this.score);
this.e_playScore.html(this.score);
this.fullArr = [];
this.nextTetris();
return;
},
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: