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

关于下面这段代码中更新#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;
	},





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值