嘿,我正在尝试将 javascript 与我的 jsp 文件一起使用,如下所示:
JSP 文件:
<?xml version="1.0" encoding="UTF-8" ?>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>title goes here</title>
<link rel="icon" href="scripts/assets/favicon.ico" type="image/x-icon"/>
<%--
Ajax code to refresh the main page's contents.
This ajax code is specific to the home page not
for all so it is kept outside the main script file.
--%>
<script type="text/javascript" src="scripts/AjaxRefresh.js"></script>
<script type="text/javascript" src="scripts/MainScript.js"></script>
<link rel="stylesheet" type="text/css" href="scripts/MainStyle.css" />
</head>
<body>
<div class="mainContainer">
<div class="header">
header
</div>
<div class="leftNavigation">
<a href="Home" title="Go to Home Page" class="navigationButton" id="home" onclick="animateLink()">Home</a>
<br/>
<a href="Home" title="Go to Home Page" class="navigationButton">Home</a>
<br/>
<a href="Home" title="Go to Home Page" class="navigationButton">Home</a>
<br/>
<a href="Home" title="Go to Home Page" class="navigationButton">Home</a>
<br/>
<a href="Home" title="Go to Home Page" class="navigationButtonActive">Home</a>
<br/>
<a href="Home" title="Go to Home Page" class="navigationButton">Home</a>
<br/>
<a href="Home" title="Go to Home Page" class="navigationButton">Home</a>
<br/>
<a href="Home" title="Go to Home Page" class="navigationButton">Home</a>
</div>
<div class="mainContentArea">
Main Content Area
</div>
<div class="rightTabBar">
Right Tab Bar
</div>
<div class="footer">
Footer
</div>
</div>
</body>
</html>
MainScript.js 文件如下:
window.onload = initAll();
function initAll(){
var navigationButton = document.getElementsByTagName("a");
for ( var int = 0; int < navigationButton.length; int++) {
if(navigationButton[int].className == "navigationButton")
navigationButton[int].onclick = animateLink;
}
}
function animateLink(){
this.className = "navigationButtonActive";
return false;
}
但是当我尝试执行此代码时,我发现 javascript 代码无法正常工作,并且firebug
我发现该变量navigationBUtton
是一个空数组。
其实我是PHP背景的,所以不太清楚jsp的概念,所以这是什么问题?
PS:我在 ubuntu 10.10 平台上使用 eclipse 3.5 和 apache tomcat6 作为 web 服务器。
谢谢 :)