$(document).ready();ã«ã¤ãã¦
jQuery使ç¨æã«ä»¥ä¸ã®æ¸ãæ¹ãããã¨ãã©ãã使ã£ã¦ãDOMæ§ç¯å¾ã®ã¿ã¤ãã³ã°ã§å®è¡ãããå¦çãå®è¡ã§ããã
$(document).ready(function(){ /*å®è¡ãããå¦ç*/ }); $().ready(function(){ /*å®è¡ãããå¦ç*/ }); $(function(){ /*å®è¡ãããå¦ç*/ });
以ä¸ã®ããã«è¤æ°åå®è¡ããå ´åã¯$(function(){/**/});ãå®è¡ããé ã«ã
ä¸ã®é¢æ°ãå®è¡ãããã®ã§ä»¥ä¸ã®å ´åã¯ãDOMæ§ç¯å¾ã«consoleã«æ¹è¡ãæãã§1,2,3ã¨é çªã«åºãã
$(function(){ console.info(1); }); $(function(){ console.info(2); }); $(function(){ console.info(3); });
èªä¿¡ããªãã®ã§ãä¸å¿ãã³ã¼ãã®è©²å½ç®æã確èª
- jQuery.fn.ready 2282-2297
- jQuery.isReady==trueã®å ´åã渡ãããé¢æ°ãdocumentãthisãjQueryã第ä¸å¼æ°ã¨ãã¦å³å®è¡ã
- jQuery.isReady==falseã®å ´åãjQuery.readyã§é 次å®è¡ãããå ´åã«ãdocumentãthisãjQueryã第ä¸å¼æ°ã¨ãã¦å®è¡ãããããã«ç¡åé¢æ°ã§å ãã ä¸ã§jQuery.readyListã«pushã
- jQuery.ready 2304-2324
- bindReady 2329-2387
- DOMæ§ç¯å¾ã®ã¿ã¤ãã³ã°ã§jQuery.readyé¢æ°ãå®è¡ããããã«ã¤ãã³ããç»é²ãããªã©ãã(ä¸åº¦ã ã)ã
ã$(function(){/**/});ãå®è¡ããé ã«ãä¸ã®é¢æ°ãå®è¡ããããã¨ããã®ã¯ç¢ºèªã§ããã
ãdocumentãthisãjQueryã第ä¸å¼æ°ã¨ãã¦å®è¡ãããããã¨ã¯åãã¦ç¥ã£ããã©ãã使ãã©ãããæãæµ®ãã°ãªãã
追è¨2008/09/16
bindReadyã«ã¤ãã¦ã¯第10回 jQueryライブラリ(2183行目~2364行目):jquery.jsを読み解く|gihyo.jp … 技術評論社ã詳ããã