【发布时间】:2013-10-09 12:42:50
【问题描述】:
我的 Express Web 应用程序的 Jade 文件中有一些 JQuery,但似乎没有被调用。下面是jade文件的内容:
extends layout
block content
p Landing page
#info Info area
block foot
a(href="https://localhost:8888/logout", title="logout") Logout
这是布局玉文件:
!!!5
html
head
title #{title}
link(rel='stylesheet', href='/stylesheets/style.css')
script(type='text/javascript', src="http://code.jquery.com/jquery-1.9.1.min.js")
script(type='text/javascript', src="/idle-timer.js")
script(type='text/javascript').
$(document).ready(function() {
$(document).idleTimer(10000);
$(document).on("idle.idleTimer", function(){
console.log("alert");
});
$(#info).click(function(){
$(this).hide();
});
});
body
header
h1 Web App Sample
.container
.main-content
block content
.sidebar
block sidebar
footer
block foot
谁能看出问题出在哪里?也许缩进?
【问题讨论】:
-
script(type='text/javascript').- 行尾的这个点有什么作用吗?您可能更容易将 JS 添加到外部文件中,然后像idle-timer.js那样调用它。 -
点显然是必需的,因为当我不添加它时,我会在控制台中收到此警告,“不推荐使用
script和style的隐式 textOnly。使用script.或 @987654328 @ 代替。” -
如果您获得正确的 html,请尝试检查源代码中生成的代码。此外,您错过了将 qoutations 添加到
$('#info') -
啊,是的,谢谢。另外,如果我将代码放在那里而不是放在头部,是否应该将 doc.ready() 放在外部 js 文件中,或者该部分应该放在头部,而只是将函数放在外部?
-
我能够在单击按钮时执行外部 javascript 函数,但我的 document.ready 中仍然没有任何内容。
标签: javascript jquery pug