document.ready()内部函数与< script>< / script>中的函数之间的区别标签 [英] difference between document.ready() inner function and a function in <script></script> tag

查看:65
本文介绍了document.ready()内部函数与< script>< / script>中的函数之间的区别标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这两个函数有什么区别?

What is the difference between these two functions?

1:

$(document).ready(function myfunc() {
   function dosomething() {
      // do something
   }
});

2:

<script language="javascript">
function dosomething() {
   // do something
}
</script>


推荐答案

$(文件) .ready()函数在DOM加载完成后执行。请参阅 http://api.jquery.com/ready/

The $(document).ready() function executes when the DOM has finished loading. See http://api.jquery.com/ready/

然后在调用之前不执行该函数。如果您要调用该函数,它将在加载时发生,而不是像前者那样等待任何外部事件完成。喜欢:

Whereas the function is not executed until called. If you were to have a call to that function, it would happen as it is loading and not wait for any external event to complete as in the former. Like:

<script language="javascript">
dosomething();
function dosomething(){
// do something
}
</script>

这篇关于document.ready()内部函数与&lt; script&gt;&lt; / script&gt;中的函数之间的区别标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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