包含HTML中的外部脚本文件在Node.js中不起作用

时间:2015-07-17 09:51:13

标签: javascript html node.js

当我从网上调用脚本并用html编写本身时。我的代码正在运行。像这样 此.HTML文件在node.js中工作。

工作代码:-------

 <!doctype html>
    <html>
        <head>
            <title>Basic Chat</title>
        </head>
        <body>
            <ul id="chat_head"></ul>
            <form action="">
                <input id="m" autocomplete="off" /><button>Enter</button>
            </form>
            <script src="https://cdn.socket.io/socket.io-1.2.0.js"></script>
            <script src="http://code.jquery.com/jquery-1.11.1.js"></script>
            <script>
                var socket = io();
                $('form').submit(function(){
                socket.emit('chat message', $('#m').val());
                $('#m').val('');
                return false;
                });
                socket.on('chat message', function(msg){
                $('#chat_head').append($('<li>').text(msg));
                });
            </script>
        </body>
    </html>

但是当我制作一切本地文件时,一切都无法正常工作

不工作:--------

<!doctype html>
<html>
    <head>
        <title>Basic Chat</title>
    </head>
    <body>
        <ul id="chat_head"></ul>
        <form action="">
            <input id="m" autocomplete="off" /><button>Enter</button>
        </form>
        <script src="script/jquery-1.11.1.js"></script>
        <script src="script/socket.io-1.2.0.js"></script>
        <script src="script/srcpt.js"></script>
    </body>
</html>

我已将所有脚本文件添加到<head>标记中,但没有用。 帮帮我。

注意: - 我在node.js服务器上运行它。不像f:///那样在本地。直接从浏览器运行html文件时,所有脚本都正常工作

1 个答案:

答案 0 :(得分:0)

<script src="script/jquery-1.11.1"></script>

应该是

<script src="script/jquery-1.11.1.js"></script>

也许