在web.xml中配置的欢迎页面index.jsp后,运行项目 onload事件没有执行 但是通过具体的路径访问页面onload事件会执行 不知道为啥?index.jsp页面如下:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<script type="text/javascript" src="../js/jquery.js"></script>
<script>
window.onload = function(){
$('#menu').html('I Love You!');
}
</script>
</head>
<body>
<div id=menu>sse</div>
</body>
</html>

解决方案 »

  1.   

    window.onload = function(){
        alert("I Love You!");
    }
      

  2.   


    你是说程序启动时,直接显示index.jsp页面没有执行onload。但是在浏览器中输入完整的地址就执行了。
    这个应该不会吧,只要页面加载、刷新都会触发的。
      

  3.   

    <script type="text/javascript" src="../js/jquery.js"></script>这个换成 <script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery.js"></script>可能是你的这张页面跳转后 jquery的路径不对了 所以这样写 就绝对的能访问到
      

  4.   

    当然了 jquery路径要是 webroot/js/jquery.js 这样的路径
      

  5.   

    window.onload = function(){
    alert();//alert试试
        $('#menu').html('I Love You!');
    }
      

  6.   

    肯定是jquery引用路劲的问题。、