$(document).ready(function(){
var hamburger = $(".hamburger");
var line = $(".line");
var menuOpen;
function openMenu() //function used to open menu
{
menu.css("left", "0px");
line.css("background", "#FFF");
menuOpen = true;
}
function closeMenu() //closing the menu
{
menu.css("left", "-320px");
line.css("background", "#BCAD90");
menuOpen = false;
}
function toggleMenu(){ // toggle between opening ang closing menu
if (menuOpen){
closeMenu();
}
else
{
openMenu();
}
}
hamburger.on({ //hamburger menu
mouseenter: function(){
openMenu();
}
});
menu.on({
mouseleave: function(){
closeMenu();
}
});
hamburger.on({
click: function(){
toggleMenu();
}
})
});
以上是對JavaScript和HTML文件中的代碼片段,但在編譯上面的代碼後,它顯示在瀏覽器中的錯誤消息"Uncaught Reference Error: $ is not defined"
.kindly解決這個錯誤,並提出必要的解決方案。
你需要在代碼中添加的jQuery。 –