![](/img/trans.png)
[英]What are the difference between $(document).bind('ready', function) and $(document).ready(function() {})
[英]What is the difference between $(document).ready(function() and $(function() ?
所以我知道這是做什么的:
$(document).ready(function(){
// Your code here...
});
現在我看到人們這么做了:
<script type="text/javascript">
$(function(){
// Your code here...
});
</script>
這兩種方式做同樣的事情嗎?
我在這里看到一個匿名函數在jquery選擇器中聲明,但實際上從未被調用過,但是通過頁面運行的方式,似乎這可能只是在pageload上運行。
是的,他們正在做同樣的事情。 當調用的參數是單個函數對象時, $()
函數包裝$(document).ready()
。
(編輯反映評論中的問題)
是的,他們做的完全一樣。
$(function(){
// Your code here...
});
是一個快捷方式
$(document).ready(function(){
// Your code here...
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.