[英]JQuery error with node, jade & express
Im geting an error saying the the $ in my js scripts are not defined, i would really love some insight into what i may be doing wrong.As a result i cant do any jquery stuff. 我收到一个错误消息说我的js脚本中的$没有定义,我真的很想知道我可能做错了什么,因此我无法做任何jquery的事情。 Ive checked the resources and they all do in fact load.
我已经检查了资源,它们实际上都在加载。
Error message: Uncaught ReferenceError: $ is not defined 错误消息:未捕获ReferenceError:未定义$
Master Page: 母版页:
//doctype html
html
head
title=title
link(href='https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.0/css/materialize.min.css', rel='stylesheet')
link(href='//fonts.googleapis.com/css?family=Roboto:400,300|Lato:100,300' rel='stylesheet')
link(href='/css/bootstrap.min.css' rel='stylesheet')
link(href='/css/custom.css' rel='stylesheet')
link(href='/css/animate.css' rel='stylesheet')
link(href="/css/pnotify.custom.min.css" media="all" rel="stylesheet" type="text/css")
link(href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet")
body
block content
link(src='https://code.jquery.com/jquery-2.1.1.min.js' type='text/javascript')
link(src="/js/pnotify.custom.min.js")
link(src="/js/custom.js")
link(src='https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.0/js/materialize.min.js' type='text/javascript')
Child Page with the javascript 子页面与javascript
extends layout
block content
nav.blue.darken-4(role="navigation" style="margin-bottom: 50px")
.nav-wrapper(style="margin-left:10px")
a.brand-logo(href='/home') Owen's Math Game - Admin Dashboard
ul.right.hide-on-med-and-down
li(class="tooltipped active" data-position="bottom" data-delay="50" data-tooltip="Profile")
a(href='/home')
i.material-icons perm_identity
li(class="tooltipped" data-position="bottom" data-delay="50" data-tooltip="Users")
a(href='/users')
i.material-icons search
li(class="tooltipped" data-position="bottom" data-delay="50" data-tooltip="Leaderboard")
a(href='/admin/leaderboard')
i.material-icons list
li(class="tooltipped" data-position="bottom" data-delay="50" data-tooltip="Settings")
a(href='/settings')
i.material-icons settings
li(class="tooltipped" data-position="bottom" data-delay="50" data-tooltip="Log Out")
a(href='/signout')
i.material-icons fast_rewind
div.container
div.row
div.col-sm-6.col-md-4.col-md-offset-4
#user
div.signup-wall
a(class="tooltipped" href="#" data-position="bottom" data-delay="50" data-tooltip="I am tooltip")
img(class='profile-img', style="display:inline" src='/avatar-img.png')
h1.text-center.login-title Welcome #{user.firstName} #{user.lastName} <br/> Check your details below:
ul.user-details
li Username #{user.username}
li Email #{user.email}
li First Name #{user.firstName}
li Last Name #{user.lastName}
script.
$(document).ready(function(){
//Initialize collapse button
$(".button-collapse").sideNav();
$('.tooltipped').tooltip({delay: 50});
})
Adding jquery in the head doesnt change the error 在头部添加jQuery不会改变错误
You declare your body content before loading jQuery (which is the library that defines $
). 您在加载jQuery(定义
$
的库) 之前声明身体内容。 You also use link
instead of script
for all your JS files. 您还可以对所有JS文件使用
link
而不是script
。
You should move (at least) the jquery load to before block content
(in the layout/"master" file). 您应该(至少)将jquery加载移至
block content
之前 (在layout /“ master”文件中)。 As @Radu also suggests in the comments, in the <head>
would be a good location. 正如@Radu在评论中所建议的那样,在
<head>
中将是一个不错的位置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.