繁体   English   中英

我如何在node.js中使用html5和jquery

[英]how can i use html5 and jquery in node.js

我想在node.js中使用我的原始html

这是简单的hsh.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title> How to Say Hello </title>
    <link type="text/css" href="./sys/lib/css/uniform.default.css" rel="stylesheet" media="screen" />
    <link type="text/css" href="./sys/lib/css/jquery-ui.1.10.3.smoothness.css" rel="stylesheet" media="screen" />
    <script type="text/javascript" src="./sys/lib/scripts/jquery-1.7.2.min.js"></script>
    <script type="text/javascript" src="./sys/lib/scripts/jquery-ui.1.10.3.min.js"></script>
    <script type="text/javascript" src="./sys/lib/scripts/myhello.js"></script>
    <script>
    $(function(){
        $( "#sayDate" ).datepicker();
    });

    function resetHello()
    {
        document.getElementById("hello").value = "";
        document.getElementById("sayDate").value = "";
    }
    </script>
</head>
<body>
    <form name="syaHello">
        How to say hello in your contry?<br>
        <input type="text" id="hello" value="">
        <INPUT id=sayDate style="WIDTH: 100px" name=sayTime>
    </form>
    <div class="docBtn_list">
        <input type="button" value="View Hello" onclick="javascript:howHello();" /> 
        <input type="button" value="Reset" onclick="resetHello();" /> 
    </div>
</body>
</html>

myhello.js

function howHello()
{
    alert(document.getElementById("hello").value + " " + 
          document.getElementById("sayDate").value);
}

nodeSev.js

var http = require('http'),
    fs = require('fs');


fs.readFile('./hsh.html', function (err, html) {
    if (err) {
        throw err; 
    }       
    http.createServer(function(request, response) {  
        response.writeHeader(200, {"Content-Type": "text/html"});  
        response.write(html);  
        response.end();  
    }).listen(3000);
});

但这不适用于jquery和howHello Java脚本。

我不想过多地更改html和js,也不要使用express包。

在回答您的问题之前...

您的问题旨在提供静态Web内容。

您应该安装“ express”(基于著名的“ connect”的节点模块,也可以用于此功能,但缺乏其他功能),并将其配置为从静态目录提供文件:

var express = require('express');
var app = express.createServer();

/* configure your static directory */
app.configure(function(){
  app.use(express.static(__dirname + '/static'));
});

/* on request, send index.html */
app.get('/', function(req, res){
   res.sendfile(__dirname + '/index.html');
});

app.listen(3000); 

现在,您已经安装了express ,看看Jade

然后,您可以处理收到的请求并动态提供内容。 这是最新技术-提供90年代样式的预编码html。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM