no message
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
document.getElementById('img').onclick=function(){
|
||||
alert("呵呵呵!")
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 608 KiB |
@@ -0,0 +1,24 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||
<title>处理静态资源</title>
|
||||
<style>
|
||||
.img{
|
||||
width: 1200px;
|
||||
/* height: 500px; */
|
||||
}
|
||||
.img img{
|
||||
width: 100%;
|
||||
/* height: 100%; */
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>处理静态资源</h1>
|
||||
<li class="img"><img src="img.jpg" alt="" id="img"></li>
|
||||
<script src="click.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,45 @@
|
||||
var http =require('http');
|
||||
var fs=require('fs');
|
||||
var server=http.createServer();
|
||||
server.on('request',function(req,res){
|
||||
// res.end('hello!');
|
||||
var urls=req.url;
|
||||
if(urls=='/'){
|
||||
fs.readFile('./index.html',function(err,data){
|
||||
if(err){
|
||||
console.log(err)
|
||||
}
|
||||
else{
|
||||
res.writeHead(200, { 'content-type': 'text/html;charset=utf-8' });
|
||||
res.end(data);
|
||||
}
|
||||
})
|
||||
}
|
||||
//挨个写入路由
|
||||
// else if(urls=='/img.jpg'){
|
||||
// fs.readFile('./img.jpg',function(err,data){
|
||||
// if(err){
|
||||
// console.log(err)
|
||||
// }
|
||||
// else{
|
||||
// res.writeHead(200, { 'content-type': 'text/html;charset=utf-8' });
|
||||
// res.end(data);
|
||||
// }
|
||||
// })
|
||||
// }
|
||||
//通用方法
|
||||
else{
|
||||
fs.readFile('.'+req.url,function(err,data){
|
||||
if(err){
|
||||
console.log(err);
|
||||
}
|
||||
else{
|
||||
res.writeHead(200, { 'content-type': 'text/html;charset=utf-8' });
|
||||
res.end(data);
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
server.listen(8082,function(){
|
||||
console.log('8080端口启动成功!')
|
||||
})
|
||||
@@ -0,0 +1,8 @@
|
||||
处理静态资源
|
||||
js
|
||||
css
|
||||
img
|
||||
res.end() butter/String
|
||||
res.send() string/Array/Object/Buffer
|
||||
# 如果服务器端没有数据要返回到客户端的话,就直接用res.end()。
|
||||
# 如果服务器需要有数据返回到客户端的话,就需要用res.send().
|
||||
Reference in New Issue
Block a user