【问题标题】:how to connect javascript files in nodejs如何在nodejs中连接javascript文件
【发布时间】:2018-04-16 04:01:09
【问题描述】:

我的问题是不能使用 javascript。 我的 javascript 文件在 public/javascripts 中

app.js

app.use(express.static(path.join(__dirname, 'public')));

views/layout.pug

doctype html
 html
  head
    title Sunghee
    meta(charset='utf-8')
    meta(name='viewport', content='width=device-width, initial-scale=1, shrink-to-fit=no')
    link(rel='stylesheet', href='https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css', integrity='sha384-/Y6pD6FV/Vv2HJnA6t+vslU6fwYXjCFtcEpHbNJ0lyAFsXTsjBbfaDjzALeQsN6M', crossorigin='anonymous')
    link(rel='stylesheet', href='https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css')
    script(src='https://code.jquery.com/jquery-3.2.1.slim.min.js', integrity='sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN', crossorigin='anonymous')
    script(src='https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.11.0/umd/popper.min.js', integrity='sha384-b/U6ypiBEHpOf/4+1nzFpr53nxSS+GLCkfwBdFNTxtclqqenISfwAzpKaMNFNmj4', crossorigin='anonymous')
    script(src='https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/js/bootstrap.min.js', integrity='sha384-h0AbiXch4ZDo7tp9hKZ4TsHbi047NrKGLO3SEJAg45jXxnGIfYzk4Si90RDIqNm1', crossorigin='anonymous')
    //- script(src='https://unpkg.com/jquery@3.2.1/dist/jquery.js')
    script(src='https://code.jquery.com/jquery-3.2.1.min.js')
    link(rel='stylesheet', type='text/css', href='/stylesheets/layout.css')
    script(src='/javascripsts/layout.js')
    block css      
    block script

视图/事件/new.pug

extends ../layout

block css
  link(rel='stylesheet' type='text/css' href='/stylesheets/events/new.min.css')

block script
  script(src='/javascripts/events/new.js')

public/javascripsts/events/new.js

$(function(){
   tinymce.init({
   seletor: '#mytextarea'
  });
});

并非所有的 JavaScript 文件都能正常工作,这个文件也一样。 package.json 的“依赖项”中有"jquery": "^3.2.1" 我该怎么办?

【问题讨论】:

    标签: javascript node.js pug


    【解决方案1】:

    输入错误?在您的 views/layout.pug 上:

    脚本(src='/javascripsts/layout.js')

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-09-16
      • 2019-08-21
      • 2010-09-23
      • 2021-05-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多