我可以避免在每个JavaScript文件中放入$(document).ready()调用吗? [英] Can I avoid putting $(document).ready() calls in each JavaScript file?

查看:74
本文介绍了我可以避免在每个JavaScript文件中放入$(document).ready()调用吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,简单的问题是,是否可以编写jQuery代码而无需在每个.js文件中编写 $(document).ready(function()?包含Js文件喜欢< script src =app / jsCode / test.js>< / script> ?谢谢。

So, simple question, is it possible to write jQuery code without writing $(document).ready(function() in every .js file? Js file is included like that <script src="app/jsCode/test.js"></script>? Thank you.

推荐答案

只需要在DOM完全加载时才能执行的代码。即使这样,你也可以使用快捷方式简写:

You only need that for code that should only be executed when the DOM is fully loaded. And even then, you can use the shortcut shorthand:

$(function() {...});

这篇关于我可以避免在每个JavaScript文件中放入$(document).ready()调用吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆