$(document).ready(function(){
    alert("1")
})
$(document).ready(function(){
    alert("3")
})
$(document).ready(function(){
    alert("2")
})
如上面的ready方法执行是从上到下的,
但因为有一个原因我要让中间的那一个在所有的ready执行后再执行,
那用什么事件呢?

$(document).readyed(function(){})??谢谢

解决方案 »

  1.   

    你不能这样吗?$(document).ready(function(){
        alert("1");
     alert("2");
     alert("3");
    })
      

  2.   

    js的加载顺序决定的
    可以尝试
    $(document).ready(function(){
      setTimeout(function(){alert("3");},1000);
    })
      

  3.   

    实在不理解这样有何意义。
    2楼实际上是可行的,因为javascript实际上是单线程,用了setTimeout等于把document.ready方法里面执行的语句提取出来等其他语句执行完毕后才执行。不过这样一个问题是ready的意义不在了(document.ready提供的方法用于替代window.onload,使得代码在图片加载完成前就开始执行)<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
    <script type="text/javascript">
    $(document).ready(function(){
    alert(1);
    });
    $(document).ready(function(){
    setTimeout(function(){
    alert(3);
    },10);
    });
    $(document).ready(function(){
    alert(2);
    });
    </script>
    </head><body>
    </body>
    </html>
    如果你有能力修改代码,改个执行顺序有什么难度吗?
      

  4.   

    你要会曲线救国。
    用一个代码字符串数组,然后对数组进行操作。 然后用eval来执行一下代码字符串。
      

  5.   

    或者你设置一个JS心跳函数。
    用一个你定义好长度的数组来控制,
    Array arr = new Array(100);
    arr[1]= 1;
    arr[3]= 3;
    然后根据arr[i]是否为空来顺序执行,如果有值就执行,无值就等待再次心跳。这不很简单吗?