검색결과 리스트
ready에 해당되는 글 2건
- 2012.10.09 Checking if jQuery is loaded vs. ready
글
I am currently developing an ASP.NET User Control. My control has dependency on jQuery, so in order for my control to operate correctly and be robust, I needed to check that jQuery has/will be loaded.
First let's define the two states of jQuery:
• loaded: jQuery is referenced in the current page by way of <script></script> tags.
• ready: jQuery is loaded and the DOM is ready for manipulation.
A non-denominational web search led me to several articles that suggested one of the following constructs:
if(jQuery) alert('jQuery is loaded.');
if(typeof(jQuery) != 'undefined') alert('jQuery is loaded.');
That makes sense; however, these simply don't work — at least not in all browsers. In actual practice, these tell us if jQuery is ready, not loaded.
Instead, I determined that the most reliable means of checking if jQuery is loaded is to check if the $ function is defined:
if(typeof($) == 'function') alert('jQuery is loaded.');
Note: this will yield a false positive in the unlikely event that the $ token has been defined by something other than jQuery as a token.
I like to use this anywhere that the standard jQuery $(document).ready() construct is used:
if(typeof($) != 'function') alert('This component requires jQuery.');
else $(function() { alert('The DOM is ready for jQuery manipulation.'); });
출처 : http://www.codeproject.com/Tips/263426/Checking-if-jQuery-is-loaded-vs-ready
'-- JQuery' 카테고리의 다른 글
신규 Form을 만들어 기존 Form의 파라미터로 POST하기 (0) | 2013.09.27 |
---|---|
같은 아이디인 여러 체크박스를 전체선택 (0) | 2013.02.08 |
JQuery Sortable (0) | 2012.09.04 |
JQuery Sortable로 Sort 시 Google Chart가 사라지는 현상 (0) | 2012.09.03 |
JQuery datepicker 이미지버튼 적용 및 스타일적용 (0) | 2012.08.20 |
RECENT COMMENT