2011年7月29日

How jQuery Works (Jquery 如何運作)


知道怎麼抄寫卻不知道原理,就永遠都無法創造屬於自己的script.

Jquery 運作原理:

Javascript的兩個問題:

the Javascript code isn't run until all images are finished downloading (this includes banner ads). The reason for using window.onload in the first place is that the HTML 'document' isn't finished loading yet, when you first try to run your code.

Javascript 在 圖片(包含Ad banner) 還未完成下載前是不會運作的。使用window.onload的原因是,當你嘗試執行你的程式碼時,HTML 'document' 卻還沒有下載完成。

解決javascript 問題 :
 jQuery has a simple statement that checks the document and waits until it's ready to be manipulated
Jquery 有簡單的指令來檢查 'document' 並且等待直到'document' 可以被執行,指令如下

$(document).ready(function(){
   // Your code here
 });


source : http://docs.jquery.com/How_jQuery_Works