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

Javascript 包含来自HTML的外部脚本文件在Node.js中不起作用,javascript,html,node.js,Javascript,Html,Node.js,当我从网上调用脚本并用html本身编写时。我的代码正在运行。这样地 此.HTML文件在node.js中工作 工作代码:----- <!doctype html> <html> <head> <title>Basic Chat</title> </head> <body> <ul id="chat_hea

当我从网上调用脚本并用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>

基本聊天
    进入 var socket=io(); $('form')。提交(函数(){ emit('chat message',$('#m').val()); $('m').val(''); 返回false; }); socket.on('chat message',函数(msg){ $('chat_head')。追加($('li>')。文本(msg)); });
    但是,当我将所有内容都制作为本地文件时,所有内容都不起作用

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

     <!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>
    
    
    基本聊天
    
      进入
      我也将所有脚本文件添加到了
      标记中,没有任何用处。
      帮帮我

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

      
      
      <script src="script/jquery-1.11.1"></script>
      
      应该是

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

      也许那是我的打字错误,对此我深表歉意。而且它在所有情况下都不工作当运行“本地”时,您的意思是
      文件://
      不是本地http服务器,对吗?请查看JS控制台。有什么错误吗?查看开发人员工具的Net选项卡。srcpt.js是否正确加载,状态为200 OK且预期内容?状态为404,未包含所有js文件。我已经解释清楚了404是不言自明的。要么URL错误,要么您没有配置节点为任何URL提供文件。@Quentin如果是这样,为什么当我在本地运行此文件时,它能够读取脚本?当我从节点服务器运行html时,404就来了。我的实际问题是,为什么从服务器运行时会得到404,而从本地运行时会得到文件。可能是因为您没有配置节点来提供文件