簡體   English   中英

用jade導入jQuery(使用node.js + express)

[英]importing jQuery with jade(with node.js + express)

我對玉有疑問。 我按如下方式導入,但似乎被忽略了。(當我使用Chrome檢查源代碼時,找不到那些資源:<)

擴展布局

head block append
  link(rel='stylesheet', href='/stylesheets/chat.css')
  script(src="/socket.io/socket.io.js")
  script(src="/javascripts/jquery-2.1.4.min.js")
  script(src="/javascripts/chat.js")

如何導入這些腳本?

謝謝 !

// ===============這是我在使用Chrome瀏覽器的“頁面源代碼”功能時所得到的。

<!DOCTYPE html>
<html>
<head>
    <title>Chat Sample</title>
    <link rel="stylesheet" href="/stylesheets/style.css">
</head>
<body>
    <h1>Chat</h1>
    <label for="userName">User name: (Hit Enter)</label>
    <input id="userName" type="text" size="30">
    <span id="feedBack"></span>
    <p> </p>
    <div id="msgWindow" class="shadow">
    </div>
    <p> </p>
    <div>
        <br>
        <table>
            <tr>
                <td>
                    <select id="users" style="width: 100px"></select>
                </td>
                <td>
                    <input id="msg" type="text" style="width: 600px" disabled="true">
                </td>
            </tr>
        </table>
    </div>
</body>
</html>

但是,css文件也不適用於該頁面。 當我使用類似http://localhost:3000/javascripts/jquery-2.1.4.min.js url時,我可以獲得文件的全部內容。

我已經更改了jQuery版本//

// ===========編輯

跟隨是錯誤。 我不明白為什么head出乎意料//

Warning: Unexpected block "head"  on line 3 of /Users/juneyoungoh/Documents/Nodejs/ChatSample/views/chat.jade. This block is never used. This warning will be an error in v2.0.0

僅供參考,這是layout.jade

doctype html
html
  head
    title= title
    link(rel='stylesheet', href='/stylesheets/style.css')
  body
    block content

從不附加任何塊,但是jade-lang.com提到以下語法:

extends layout

block append head
  link(rel='stylesheet', href='/stylesheets/chat.css')
  script(src="/socket.io/socket.io.js")
  script(src="/javascripts/jquery/jquery-1.7.2.min.js")
  script(src="/javascripts/chat.js")

http://jade-lang.com/reference/inheritance/

我從Jannik的評論中得到了提示。 可能是版本問題。 最后,我編輯了layout.jade

doctype html
html
  head
    title= title
    link(rel='stylesheet', href='/stylesheets/style.css')
  body
    block content

doctype html
html
  block head
    title= title
    link(rel='stylesheet', href='/stylesheets/style.css')
  body
    block content

我添加了block關鍵字。

僅供參考,我正在使用

  • npm版本2.12.1
  • 節點版本0.10.23
  • 表達3.4.7版

和package.json像

{
  "name": "application-name",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node app.js"
  },
  "dependencies": {
    "express": "3.4.7",
    "jade": "*"
  }
}

謝謝你的幫助! :d

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM