我面临一个有趣的问题,很可能是因为我无法察觉的愚蠢错误。 HTML文件使用Markdown生成。 我在html中包含了一个JavaScript文件。可以看出它是在浏览器中加载的(在mozilla firefox上试过)。
见下面的证明。 https://github.com/datastax/java-driver
启用了JShttps://www.whatismybrowser.com/detect/is-javascript-enabled
但不知何故,它还没有被执行。
以下是我的HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-16"/>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="generator" content="Bootply-JBake-Custom"/>
<meta http-equiv="content-type" content="text/html; charset=UTF-16"/>
<title>Title</title>
<link href="/css/bootstrap.min.css" rel="stylesheet">
<link href="/css/asciidoctor.css" rel="stylesheet">
<link href="/css/base.css" rel="stylesheet">
<link href="/css/prettify.css" rel="stylesheet">
<link href="/css/styles.css" rel="stylesheet">
<link href="/css/animate.css" rel="stylesheet">
<link rel="shortcut icon" href="favicon.ico">
<script src="/js/jquery-1.11.1.min.js"></script>
<script src="/js/bootstrap.min.js"></script>
<script src="/js/prettify.js"></script>
</head>
<body onload="prettyPrint()">
<div id="wrap">
<div class="navbar navbar-default navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<a href="/index.html" class="navbar-brand">LOGO</a>
<button class="navbar-toggle" type="button" data-toggle="collapse" data-target="#navbar-main">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div class="navbar-collapse collapse" id="navbar-main">
<ul class="nav navbar-nav">
<li><a href="/projects/projects.html">Projects</a></li>
<li><a href="/about.html">About</a></li>
<li><a href="/categories.html">Categories</a></li>
</ul>
</div>
</div>
</div>
<div class="container">
<div class="page-header" id="banner">
<div class="row">
<div class="col-lg-8 col-md-7 col-sm-6">
<h1>Projects</h1>
</div>
</div>
</div>
<!-- This script is loading but not executing -->
<script type="text /javascript" src="projects.js"></script>
<p>Here is the list of projects</p>
</div>
</div>
<div id="push"></div>
<div id="footer">
<div class="container">
</div>
</div>
</body>
</html>
projects.js
$(document).ready(function(){
console.log("ready")
alert("hi");
});
console.log("loaded")
答案 0 :(得分:2)
<script type="text /javascript" src="projects.js"></script>
删除type="text /javascript
中的空格,结果为:
<script type="text/javascript" src="projects.js"></script>
这应该允许浏览器正确解析HTML并加载脚本。
编辑:或完全删除type
标记中的<script>
属性,如以下评论所示。