【问题标题】:JQuery not working with JadeJQuery 不适用于 Jade
【发布时间】: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 那样调用它。
  • 点显然是必需的,因为当我不添加它时,我会在控制台中收到此警告,“不推荐使用 scriptstyle 的隐式 textOnly。使用 script. 或 @987654328 @ 代替。”
  • 如果您获得正确的 html,请尝试检查源代码中生成的代码。此外,您错过了将 qoutations 添加到 $('#info')
  • 啊,是的,谢谢。另外,如果我将代码放在那里而不是放在头部,是否应该将 doc.ready() 放在外部 js 文件中,或者该部分应该放在头部,而只是将函数放在外部?
  • 我能够在单击按钮时执行外部 javascript 函数,但我的 document.ready 中仍然没有任何内容。

标签: javascript jquery pug


【解决方案1】:

在我的手机上很难看到,但您是否缩进了您的脚本代码,例如:

html
    head
        script(src='jsfile')
        script
            $(document).ready
    body #same level as head!
        header

【讨论】:

    猜你喜欢
    • 2016-05-11
    • 1970-01-01
    • 2020-04-13
    • 1970-01-01
    • 2015-09-22
    • 2017-08-25
    • 1970-01-01
    • 2012-08-01
    相关资源
    最近更新 更多