2017-08-08 24 views
0

我正在爲使用模板的建築公司設計一個網頁。該html文件使用名爲app.js的js文件。每當我編輯js文件時,整個html頁面都變得無法響應,就好像js文件從不在那裏一樣。這裏是app.js文件中存在的代碼。如果編輯的app.js文件停止工作

//animate first team member 
jQuery('#first-person').bind('inview', function (event, visible) { 
    if (visible == true) { 
     jQuery('#first-person').addClass("animated pulse"); 
    } else { 
     jQuery('#first-person').removeClass("animated pulse"); 
    } 
}); 

//animate sectond team member 
jQuery('#second-person').bind('inview', function (event, visible) { 
    if (visible == true) { 
     jQuery('#second-person').addClass("animated pulse"); 
    } else { 
     jQuery('#second-person').removeClass("animated pulse"); 
    } 
}); 

//animate thrid team member 
jQuery('#third-person').bind('inview', function (event, visible) { 
    if (visible == true) { 
     jQuery('#third-person').addClass("animated pulse"); 
    } else { 
     jQuery('#third-person').removeClass("animated pulse"); 
    } 

該文件可以正常使用此預寫腳本。但是當我嘗試添加以下行一個新的ID「第四人稱」我在HTML文件中

//animate fourth team member 
jQuery('#fourth-person').bind('inview', function (event, visible) { 
    if (visible == true) { 
     jQuery('#fourth-person').addClass("animated pulse"); 
    } else { 
     jQuery('#fourth-person').removeClass("animated pulse"); 
    } 

HTML頁面變得不響應創建。請告訴我什麼可能是問題,並儘可能解決方案

+0

在HTML中是否有'#fourth-person'元素? – Aenadon

+1

控制檯中的錯誤是什麼? – Nisarg

+1

您是否檢查了控制檯的語法錯誤,因爲這對我來說看起來像是語法錯誤。 – Li357

回答

2

我可以看到至少兩個語法問題,您不關閉第三人稱和第四人稱元素的事件綁定。他們應該是這樣的:

//animate fourth team member 
jQuery('#fourth-person').bind('inview', function (event, visible) { 
    if (visible == true) { 
     jQuery('#fourth-person').addClass("animated pulse"); 
    } else { 
     jQuery('#fourth-person').removeClass("animated pulse"); 
    } 
}); // <-- This is missing 
+0

哇,非常感謝..不能相信我被困在一個簡單的語法問題。代碼和js文件工作正常:) –

+0

不客氣!將來,只需嘗試查看瀏覽器控制檯中記錄的內容(F12)。它總會給你一些關於這個問題的提示。 – Nisarg