我用的是.js
中的HTML文件中包含的<head>
部分。然后,我从HTM调用.js
。但是,由于某种原因,函数不会调用,而且HTML和.js文件都位于同一个项目文件夹中。
HTML文件:
<!DOCTYPE html>
<html>
<head>
<title>First html document</title>
<script type="text/javascript" src="javascript.js"></script>
</head>
<body>
<p>Testing javascript. <script>sayHello()</script></p>
</body>
</html>
js:
function sayHello(){
document.write("Hello world!")
}
方括号显示了.js文件中的错误。这就是问题所在吗?
错误:
JSLint (5)
1
Expected exactly one space between ')' and '{'. function sayHello(){
1
Missing space between ')' and '{'. function sayHello(){
2
Missing 'use strict' statement. document.write("Hello world!")
2
document.write can be a form of eval. document.write("Hello world!")
2
Expected ';' and instead saw '}'. document.write("Hello world!")
ESLint (2)
1
ERROR: 'sayHello' is defined but never used. [no-unused-vars] function
sayHello(){
2
ERROR: 'document' is not defined. [no-undef]
发布于 2018-08-10 10:49:05
你 要确保你的js
文件位于正确的目录中,使用当前代码,这意味着js
文件位于与你的文件夹相同的文件夹中。
https://stackoverflow.com/questions/-100002056
复制相似问题