我正在设置localhost服务器,并且在root Directory,script.js和padding.html中有2个文件。HTML文件直接引用脚本。当我使用php -S localhost:8000 padding.html
设置localhost网站时,脚本的内容。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 <
单击它,然后将您带到"脚本。此文件应为上面显示的脚本。JS文件
在padding.html中,您似乎有一个语法错误,会导致该错误出现在控制台中。用<script src="script.js"></script>
替换<script src = script.js></script>
(请注意添加的引号(。