學習jQuery的第一件事是:如果你想要一個事件運行在你的頁面上,你必須在$(document).ready()里調用這個事件。所有包括在$(document).ready()里面的元素或事件都將會在DOM完成加載之后立即加載,并且在頁面內容加載之前。 If you want an event to work on your page, you should call it inside the $(document).ready() function. Everything inside it will load as soon as theDOM is loaded and before the page contents are loaded. 代碼如下: $(document).ready(function() { // put all your jQuery goodness in here. });