【问题标题】:Why aren't all my images showing?为什么我的所有图像都没有显示?
【发布时间】:2013-05-14 05:59:59
【问题描述】:

我在 Jade 中使用 Express.js 并遇到了问题。我有 6 张图片,但其中 2 张不会显示在页面上。我可以去local:3000/images/a.png 看到它们,但在我的页面上看不到它们?这是我的一些 Jade HTML:

          .span4
            img(src='/images/a.png', class='img')
          .span4
            img(src='/images/b.png', class='img')
          .span4
            img(src='/images/c.png', class='img')
        .row-fluid
          .span4
            img(src='/images/d.png', class='img') 
          .span4
            img(scr='/images/e.png', class='img') # Not working
          .span4
            img(scr='/images/f.png', class='img') # Not working

如果有帮助,这是我的app.js

var express = require('express')
  , routes = require('./routes')
  , user = require('./routes/user')
  , http = require('http')
  , path = require('path');

var app = express();

// all environments
app.set('port', process.env.PORT || 3000);
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.favicon(__dirname + '/public/images/icon.ico'));
app.use(express.logger('dev'));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(path.join(__dirname, 'public')));


// development only
if ('development' == app.get('env')) {
  app.use(express.errorHandler());
}

app.get('/', routes.index);
app.get('/users', user.list);

http.createServer(app).listen(app.get('port'), function(){
  console.log('Express server listening on port ' + app.get('port'));
});

还有其他人遇到过这个吗?我能做什么?

【问题讨论】:

  • 你的img(src='/images/a.png', class='img')可以写成img.img(src='/images/a.png')。例如。 element.class.class#id(attribute=value)
  • 另外,在 img 标签上有一个类 img...嗯,为什么?

标签: node.js express pug


【解决方案1】:

呵呵,因为你的玉文件有错别字。

仔细检查您的 img 标签 - 它(如您所知)应该是 src 而不是 scr

      .span4
        img(scr='/images/e.png', class='img') # Not working
      .span4
        img(scr='/images/f.png', class='img') # Not working

【讨论】:

  • 该死!谢谢,这些小细节总能吸引我!我会尽快接受你的回答。
  • 呵呵@Jryl,我们都遇到过这种情况:)很高兴为您提供帮助:)
  • 如果你杀了我,我永远看不到它 :-) +1
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-09-08
  • 2021-10-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-07-09
相关资源
最近更新 更多