代码的意思应该是 先变成红色,再弹1。但是现在反过来了。。。
<style>
#box{
width: 100px;
height: 100px;
background-color: #7FFFD4;
}
</style>
<body>
<div id="box"></div>
<button>123123</button>
</body>
<script>
$("button").click(function() {
$("#box").css("background-color", "red");
alert(1)
})
</script>
执行顺序其实没错,只是
alert()
会阻塞页面更新。补充
解决方法很简单,用 setTimeout 就行了