据我所知,没有真正的理由说这段代码不起作用。我有一个HTML文件和一个外部.js文件。这是我在html中使用的语句来加载.js文件:
<script type="text/javascript" src="family.js"></script>
文件的名称是正确的,它位于同一目录中。我将在下面发布html页面的完整代码,以防万一有其他内容。
我有什么遗失的吗? .js文件应该是一个滑动菜单,但它根本就没有加载。我在.js文件中插入了一个警告,该警告应该在它工作时提醒我,尽管它没有出现。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<!-- DW6 -->
<head>
<title>The Jones Family</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="family.css" type="text/css" />
<script type="text/javascript" src="family.js"></script>
<script language="JavaScript" type="text/javascript">
var d=new Date();
var monthname=new Array("January","February","March","April","May","June","July","August","September","October","November","December");
//Ensure correct for language. English is "January 1, 2004"
var TODAY = monthname[d.getMonth()] + " " + d.getDate() + ", " + d.getFullYear();
alert ("Inside script is working");
</script>
</head>
<body >
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr class="head">
<td width="382" colspan="3" rowspan="2"><img src="camera.jpg" alt="camera" border="0" /></td>
<td width="378" height="50" colspan="3" id="logo" valign="bottom" align="center" nowrap="nowrap">The Jones Family Website</td>
<td width="100%"> </td>
</tr>
<tr class="head">
<td height="51" colspan="3" id="tagline" valign="top" align="center">Photo Gallery</td>
<td width="100%"> </td>
</tr>
<tr>
<td colspan="7" class="separator" ><div class="myHr"><hr /></div></td>
</tr>
<tr class="separator">
<td colspan="7" id="dateformat" height="20"> <script language="JavaScript" type="text/javascript">
document.write(TODAY); </script> </td>
</tr>
<tr>
<td colspan="7" class="separator" ><div class="myHr"><hr /></div></td>
</tr>
<tr>
<td width="200" height="450" valign="top" class="nav" >
<table class="nav" border="0" cellspacing="0" cellpadding="0" width="40" id="navigation">
<tr>
<td > <br />
<br /></td>
</tr>
<tr>
<td ><div class="navG" id="gallery1" style="position: absolute; top: 180px; left: -150px; " >
<table width="184" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="150"><a href="#">Disney</a><br />
<a href="#">SeaWorld</a><br />
<a href="#">Bush Garden</a><br />
<a href="#">Universal Studios</a><br />
</td>
<td><img src="gallery1.jpg" alt="gallery 1" class="nav1" /></td>
</tr>
</table>
</div></td>
</tr>
<tr>
<td ><div class="navG" id="gallery2" style="position: absolute; top: 285px; left: -150px; " >
<table width="184" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="150"><a href="#">Sweet 16</a><br />
<a href="#">Summer Camp</a><br />
<a href="#">Holiday</a><br />
<a href="#">Ski Trip</a><br />
</td>
<td><img src="gallery2.jpg" alt="gallery 2" class="nav1" /></td>
</tr>
</table>
</div></td>
</tr>
<tr>
<td ><div class="navG" id="gallery3" style="position: absolute; top: 390px; left: -150px; " >
<table width="184" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="150"><a href="#">Mom's Birthday (2011)</a><br />
<a href="#">Dad's Birthday (2011)</a><br />
<a href="#">Bobby's Birthday</a><br />
<a href="#">Jenny's</a><br />
</td>
<td><img src="gallery3.jpg" alt="gallery 3" class="nav1" /></td>
</tr>
</table>
</div></td>
</tr>
<tr>
<td ><div class="navG" id="gallery4" style="position: absolute; top: 495px; left: -150px; " >
<table width="184" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="150"><a href="#">Skatepark</a><br />
<a href="#">Wildlife</a><br />
<a href="#">Beach</a><br />
<a href="#">Hawaii</a><br />
</td>
<td><img src="gallery4.jpg" alt="gallery 4" class="nav1" /></td>
</tr>
</table>
</div></td>
</tr>
</table>
<br />
<br />
<br />
<br /> </td>
<td width="50"></td>
<td width="305" colspan="2" valign="top"><br />
<br />
<br />
<table border="0" cellspacing="0" cellpadding="0" width="305">
<tr>
<td class="pageName">Family Photos</td>
</tr>
<tr>
<td class="bodyText"><p>From here you can see family Photos taken by our various amateur photographers!</p>
<p>We hope you enjoy the photos as much as we do!</p>
<p align="center"><img src="sayCheese.jpg" alt="Say Cheese" /></p></td>
</tr>
</table>
<br />
<br /> </td>
<td width="50"></td>
<td width="190" valign="top"><br />
<br />
<table border="0" cellspacing="0" cellpadding="0" width="190" id="leftcol">
<tr>
<td width="10"></td>
<td width="170" class="smallText"><br />
<p><span class="subHeader">Photog #1</span><br />
Mary Sue - Mother, she prefers her Canon camera. She still uses film, but has the photos put onto digital cd when developed. </p>
<p><span class="subHeader">Photog #2</span><br />
Bobby - Hip son, he prefers his HP kid digital camera. Not that old, but still takes interesting pictures.</p>
<p><span class="subHeader">Photog #3</span><br />
Jenny - Cool Teen, she has a Sony digital video camera. She takes movies and still photos. Just don't expect her to smile too much.</p>
<br />
<br /> </td>
<td width="10"> </td>
</tr>
</table> </td>
<td width="100%"> </td>
</tr>
<tr>
<td width="165"> </td>
<td width="50"> </td>
<td width="167"> </td>
<td width="138"> </td>
<td width="50"> </td>
<td width="190"> </td>
<td width="100%"> </td>
</tr>
</table>
</body>
</html>
答案 0 :(得分:5)
问题不是MIME类型,而是在JS脚本中(如果它是'http://orca.st.usm.edu/~tbonnet2/440/p5/family.js'中的那个)
缺少右括号,请查看closeMenu():
function closeMenu() {
/* get the current menu id */
var ID = this.id + "List"
/* determine active menu */
activeMenu = document.getElementById(ID);
if (activeMenu) { // <------ THIS CONDITIONAL BLOCK ISN'T CLOSED!
activeMenu.style.display = "none";
activeMenu = null;
/* run the moveItemLeft function by setting a time interval */
timeID = setInterval("moveItemLeft()", 1);
}
答案 1 :(得分:0)
例如,如果有关于加载该js文件的错误(并发布),请检查Firefox的控制台。 也许,文件已加载,但它包含的错误无法让您看到警报
答案 2 :(得分:0)
请注意,您的服务器返回的HTML类型与HTML源代码中指定的不同:
<script type="text/javascript" src="family.js"></script>
$ HEAD http://orca.st.usm.edu/~tbonnet2/440/p5/family.js
200 OK
Connection: close
Date: Thu, 23 Feb 2012 02:22:59 GMT
Accept-Ranges: bytes
ETag: "1320142-9f5-4b9979ec8c280"
Server: Apache/2.2.3 (Red Hat)
Content-Length: 2549
Content-Type: application/x-javascript # <-- see here
Last-Modified: Thu, 23 Feb 2012 01:32:42 GMT
Client-Date: Thu, 23 Feb 2012 02:22:59 GMT
Client-Peer: 131.95.35.200:80
Client-Response-Num: 1
答案 3 :(得分:0)
我遇到的问题与问题的作者描述相同。
但是,在我的情况下,没有从磁盘重新读取js文件。 最初,当我开始测试HTML结构时,我的js文件是空的。 后来当我向js文件添加代码时,即使在“刷新”浏览器之后,已经打开的浏览器窗口也没有重新读取js文件。
js文件在那里,它位于同一目录中,但文件的内容是在浏览器中缓存的内存。我在Google调试器的某处看到了一条消息,但我无法再次找到该消息。消息说明HTML文件是磁盘缓存的,而js文件是内存缓存的。
当我点击浏览器的刷新按钮时,HTML文件被刷新,但是js文件没有刷新,并且在添加js内容之前从页面的初始运行开始在“sources”选项卡中显示为空。
要修复,我关闭浏览器窗口,打开一个新的浏览器窗口,一切都开始正常工作。新窗口从磁盘重新读取js脚本。
答案 4 :(得分:0)
如果您没有上述答案中的任何错误,并且正在使用网络托管服务...。 1.登录到控制面板,然后检查文件是否确实存在。
我遇到了同样的问题,当我进行更改甚至更改了文件名时,我都使用ftp(winSCP)上传文件,我遇到了同样的问题,但是当我进入控制面板(文件管理器)时,我通过winSCP所做的更改没有得到体现,然后我通过控制面板上传了所有内容,一切开始正常运行。