chr*_*ism 104 javascript jquery dom
我有一个jquery脚本,我需要只运行页面上的其他一切,包括一些其他javascripts(我无法控制)完成了他们的事情.
我可能有一个替代$(文件).ready但我找不到它.
Jos*_*lio 211
您可以$(document).ready()在页面中多次使用.代码按其出现的顺序运行.
您可以将$(window).load()事件用于代码,因为在页面完全加载并且各种$(document).ready()处理程序中的所有代码都已完成运行后会发生这种情况.
$(window).load(function(){
  //your code here
});
Jas*_*ams 11
多个$(document).ready()将在页面上自上而下触发.最后一个$(document).ready()将在页面上最后触发.在最后一个内部$(document).ready(),您可以触发一个新的自定义事件,以便在所有其他事件后触发.
将代码包装在新自定义事件的事件处理程序中.
<html>
<head>
<script>
    $(document).on("my-event-afterLastDocumentReady", function () {
        // Fires LAST
    });
    $(document).ready(function() {
        // Fires FIRST
    });
    $(document).ready(function() {
        // Fires SECOND
    });
    $(document).ready(function() {
        // Fires THIRD
    });
</script>
<body>
... other code, scripts, etc....
</body>
</html>
<script>
    $(document).ready(function() {
        // Fires FOURTH
        // This event will fire after all the other $(document).ready() functions have completed.
        // Usefull when your script is at the top of the page, but you need it run last
        $(document).trigger("my-event-afterLastDocumentReady");
    });
</script>
小智 10
这个代码块解决了我的问题,
<script type="text/javascript">
  $(window).bind("load", function () {
    // Code here
  });
</script>事实证明,由于 JavaScript 框架的特殊混合,我需要使用其他框架之一提供的事件侦听器来启动脚本。
| 归档时间: | 
 | 
| 查看次数: | 189528 次 | 
| 最近记录: |