为什么本地主机中的script.js与根目录中的script.js不同

时间:2019-05-26 06:45:42

标签: java html localhost web-development-server

我正在设置一个本地主机服务器,并且在根目录中有2个文件script.js和padding.html。 html文件直接引用script.js文件。当我使用php -S localhost:8000 padding.html设置localhost站点时,script.js文件的内容将成为padding.html文件的内容。

我尝试在代码编辑器中重新保存工作,重置服务器并重新加载页面。

script.js

function getValue (id) {
    text = document.getElementById(id).value; //value of the text input
    alert(text);
    return false;
}

padding.html

<!DOCTYPE html>
<html>
    <title>javatest</title>
    <script src = script.js></script>
    <body>
        <div class="entry foreground-color">
            <form onsubmit="return getValue('commands')">
                <input type="text" name="commands" size="60"/>
            </form>
        </div>
    </body>

</html>

运行服务器,然后依次检查元素和控制台,出现错误,提示Uncaught SyntaxError: Unexpected token < 单击它,然后将您带到'script.js'文件,该文件只是padding.html文件的副本,具有不同的名称。该文件应该是上面显示的script.js文件

1 个答案:

答案 0 :(得分:0)

在padding.html中,您似乎有一个语法错误,该错误会导致该错误出现在控制台中。将<script src = script.js></script>替换为<script src="script.js"></script>(注意添加的引号)。