admin管理员组文章数量:1415439
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>
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>
Share
Improve this question
edited Apr 25, 2010 at 0:48
Bill the Lizard
406k212 gold badges574 silver badges892 bronze badges
asked Apr 17, 2010 at 8:30
DELETE meDELETE me
2 Answers
Reset to default 9The $(document).ready()
function executes when the DOM has finished loading. See http://api.jquery./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 plete as in the former. Like:
<script language="javascript">
dosomething();
function dosomething(){
// do something
}
</script>
In the first example, your inner function dosomething()
will be limited to the scope of myfunc()
.
In the second case, the dosomething()
function will be added to the global space. It will be accessible from anywhere.
本文标签:
版权声明:本文标题:javascript - difference between document.ready() inner function and a function in <script><script> t 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745235594a2649022.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论