最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Is there a native Javascript implementation of jQuery's document.ready()? - Stack Overflow

programmeradmin1浏览0评论
 $(document).onload()

it's internally implemented by window.onload event

then what about

 $(document).ready()

what's the native javascript to implement it?

 $(document).onload()

it's internally implemented by window.onload event

then what about

 $(document).ready()

what's the native javascript to implement it?

Share Improve this question edited Aug 16, 2009 at 4:42 Paolo Bergantino 488k82 gold badges521 silver badges437 bronze badges asked Aug 16, 2009 at 4:33 omgomg 140k145 gold badges291 silver badges351 bronze badges 3
  • 1 jQuery is native JavaScript... – Shog9 Commented Aug 16, 2009 at 4:47
  • @shog9 +1 I came here to say that. – Imagist Commented Aug 16, 2009 at 5:21
  • 5 @Shog9: don't be difficult, you know what it means. :P – Paolo Bergantino Commented Aug 16, 2009 at 6:02
Add a comment  | 

3 Answers 3

Reset to default 18

For Mozilla, Opera and webkit, jQuery binds the DOMContentLoaded event, for IE jQuery uses the onreadystatechange event.

Look the internal bindReady function on the jQuery source code.

What do you mean?

.ready() is a function jQuery wrote to handle the inconsistent way that all the browsers may report 'load complete' for the given element.

.onload() may work in X browser but not Y. This is (part) of what jQuery is for - to solve this problem for you.

Looking at the jQuery source code, there is a function called bindReady that does the native Javascript work. There are different methods for different browsers, and the fallback method if none of the specific methods work is to use the window.onload event.

发布评论

评论列表(0)

  1. 暂无评论