<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;
}
可以参照 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());
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; },
相关文章推荐
- Javascript中的sort()语法浅谈
- JS立即执行
- js对分页的控制
- JavaScript 学习笔记-select
- MSI Custom Action用管理员权限去执行
- 原型语言解释
- jsonp
- 取得字符串的字节长度
- js 购物车数量增减,总价格联动变化
- js对象无法当成参数传递
- JS 右键菜单
- js获取dom元素绝对位置
- js替换alert弹窗
- grunt解决前后端跨域问题
- 解决javascript动态改变img的src属性图片不显示问题
- JavaScript学习笔记整理
- 深入理解JavaScript系列(结局篇)
- 深入理解JavaScript系列(50):Function模式(下篇)
- 深入理解JavaScript系列(49):Function模式(上篇)
- 深入理解JavaScript系列(48):对象创建模式(下篇)