【问题标题】:Include jquery mobile in express js app correctly在 express js 应用程序中正确包含 jquery mobile
【发布时间】:2012-04-22 03:22:16
【问题描述】:

我在我的 express 应用程序中包含 jquery js 文件时遇到问题。我将 jquery.js 文件添加到 /public/javascripts 文件夹,并将我的 layout.jade 文件更改为如下:

!!!5
html
  head
    title= title
    meta(name='viewport', content='width=device-width,initial-scale=1')
    link(rel='stylesheet', href='/stylesheets/style.css')
    link(rel='stylesheet', href='/stylesheets/jquery.mobile-1.0.1.min.css')
    script(type='text/javascript', src='/javascripts/jquery.mobile-1.0.1.min.js')
    script(type='text/javascript', src='/javascripts/jquery-1.7.2.min.js')
  body!= body

我还包括了 app.use(express.static(__dirname + '/public'));在我的 app.js.我更改了我的 index.jade 如下以包含一些 jquery 移动标签:

div(data-role='page')
div(data-role='header')
    h1= title

div(data-role='content')    
    ul(data-role='listview',data-inset='true',data-filter='true')
            li: a(href='#') Acura

问题是我无法正确渲染网页。我看不到任何与 jquery 相关的样式。有人知道我该如何解决吗?

谢谢,

【问题讨论】:

    标签: jquery node.js jquery-mobile express


    【解决方案1】:

    您需要在 jQuery Mobile 文件之前包含 jQuery Core 文件,因为后者扩展了前者;因此,如果包含 Mobile 时 Core 不存在,则会出现错误。

    您可以在此处参考正确的顺序以包含 jQuery 和 jQuery Mobile 文件:http://www.jquerymobile.com/download/

    您还使用了错误的 jQuery Core 版本(查看上面的链接以获得正确的版本):

    • jQuery Mobile 1.0.1 支持 jQuery Core 1.6.4。
    • jQuery Mobile 1.1.0 RC-1 支持 jQuery Core 1.7.1。 jQuery Mobile 目前不支持 jQuery Core 1.7.2(如this blog post 中所述)。

    最后,我会在 jQuery Mobile 样式表之后包含您的自定义 CSS 样式表,以便更轻松地覆盖 jQuery Mobile CSS。

    【讨论】:

    • 这对我不起作用。我更改了jquery核心版本并更改了顺序。
    • 如果我将脚本更改为 script(type='text/javascript', src='code.jquery.com/jquery-1.6.4.min.js') script(type='text/javascript', src='code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.min.js') 使用它会工作的完整路径。
    • 我想我找到了解决方案。我更改了 jquery 文件名,现在可以正常工作了。但我会将这个答案标记为正确,因为它包含有用的提示,可以帮助我解决这个问题。
    猜你喜欢
    • 1970-01-01
    • 2012-01-06
    • 1970-01-01
    • 1970-01-01
    • 2014-02-21
    • 1970-01-01
    • 1970-01-01
    • 2012-07-23
    • 2017-12-25
    相关资源
    最近更新 更多