我正在为上传文件和商店表单创建node.js
的示例。
问题是,当我从任何端口的css
访问时,js
和localhost
文件无法正常工作。我使用端口3000,当我在浏览器中打开文件index.html
没问题,但是当我按照localhost:3000
或任何端口时,端口不是问题而css
文件没有不行。所以我的代码是:
HTML
:
<!DOCTYPE html>
<html>
<head>
<title>Video Uploader</title>
<meta charset="utf-8">
<link href="/css/style.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="/javascript/formstorage.js"></script>
<script src="/javascript/jquery-ui.js"></script>
</head>
<body>
<form>
<div class="cont fl">
<h1>File's Uploader:</h1>
<div class="fl form">
<div>
<h1>
Your Name:
</h1>
<input type="text" class="inps" id="nome">
</div>
<div>
<h1>
e-mail:
</h1>
<input type="text" class="inps" id="email">
</div>
<div class="bt">
<div class="fl">
<input type="button" value="Record" id="rec">
</div>
<div class="fr">
<input type="button" value="Upload" id="file">
</div>
</div>
<input type="button" value="Confirm" id="sub">
</div>
<!-- fim do formulario -->
<div class=" fr" id="contentv">
</div>
</div>
</form>
</body>
</html>
&#13;
开放服务器的js
:
var express = require('express');
var app = express();
var path = require('path');
var formidable = require('formidable');
var fs = require('fs');
app.use(express.static(path.join(__dirname, 'public')));
app.get('/', function(req, res){
res.sendFile(path.join(__dirname, 'index.html'));
});
var server = app.listen(3000, function(){
console.log('Server listening on port 3000');
});
&#13;
答案 0 :(得分:1)
删除路径中的“public”。
cf)/css/style.css
此行的原因(app.use(express.static(path.join(__dirname, 'PATH')));
),
PATH/FILE
的{{1}}只是absolute URL
。
答案 1 :(得分:0)
坦克帮助我。 我知道,但我修改了这段代码几次,并没有工作.. 现在我做了什么: 我创建de文件夹public / css / style.css并在我的Node文件中添加app.use()和'public'这样的行,例如김재원。在html的链接中我写了“/css/style.css”。 之前还是不行。我尝试尝试尝试但不工作。 现在正在工作......我确实知道这里发生了什么,但现在同样的事情是工作大声笑。