0

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パッケージは使用しません。

4

1 に答える 1

1

質問に答える前に...

あなたの質問は、静的な 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 を見てみましょ

その後、受信したリクエストを処理し、コンテンツを動的に提供できます。これは最新技術です。事前にコード化された html を提供するのは 90 年代スタイルです。

于 2013-11-11T12:26:33.073 に答える