jquery:为什么这两行的执行是同时执行的?

  • 本文关键字:执行 两行 jquery jquery
  • 更新时间 :
  • 英文 :


这是我的代码片段

$(function() {
  $(".red-box").fadeOut(2000); //1
  $(".green-box").fadeOut(2000); //2
  $(".red-box").fadeIn(2000);//3

});

index.html如下所示

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <script src="js/jquery-3.2.1.min.js"></script>
  <script src="js/script.js"></script>
  <link rel="stylesheet" href="css/style.css">
  <title>TProject Structure</title>
</head>
<body>
  <div id="content">
    <h1>Project Structure</h1>
    <div class="red-box">Red</div>
    <div class="green-box">Green</div>
    <div class="blue-box">Blue</div>
    <div class="clear"></div>
    <h2>Hi, I'm the Base Project!</h2>
    <p>Add elements here as you like to try out jQuery. This is your playground to test out anything that comes into your mind.</p>
    <p><strong>OR:</strong> Copy this project structure into a new directory first to create separate playgrounds for animations, manipulations, event handlers etc.</p>
  </div>
</body>
</html>

打开HTML页面时,我确实注意到

a)首先,红色和绿色盒子一起消失。b)然后红色的盒子逐渐消失。

我的QS

a)jQuery如何知道第1行和第2行将共同执行,然后再执行第3行?

如果执行是"按行"的"行",则jQuery应该执行第1行(即等待2秒之前),此后仅应执行第2行,等等...

有人可以解释为什么line1和line2的执行被jQuery绑在一起?

使用呼叫背包。这应该解释:http://javascriptissexy.com/understand-javascript-callback-functions-and-use-them/

最新更新