【发布时间】:2014-04-04 20:35:59
【问题描述】:
在我使用 Spring MVC 框架开发的动态 Web 项目 (Eclipse) 中,我有下面的 JSP 页面,放在文件夹 WEB-INF/jsp/ 中:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>HorarioLivre</title>
<script src="http://code.jquery.com/jquery-2.1.0.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js"></script>
<script src="js/index.js"></script>
<link rel="stylesheet" href="css/style-main.css">
<link rel="stylesheet" href="css/style-popup.css">
</head>
<body>
<header>
<div class="container">
<h1><a href="#">HorarioLivre</a></h1>
<nav>
<ul>
<li><a href="listagem_evento.html" class="icon evento">Eventos</a></li>
<li><a href="cadastra_horario.html" class="icon horario">Cadastrar Horarios</a></li>
<li><a href="listagem_horario.html" class="icon horario">Listar Horarios</a></li>
<li><a href="listagem_usuario.html" class="icon usuario">Usuarios</a></li>
<li><a href="#">${usuario.nome}</a>
<ul>
<li><a href="usuario_perfil.html" class="icon perfil">Perfil</a></li>
<li><a href="usuario_config.html" class="icon settings">Configurações</a></li>
<li><a href="#">Logout</a></li>
</ul>
</li>
</ul>
</nav>
</div>
</header>
<div id="results">
<a href="#" id="close">Fechar</a>
<div id="content"></div>
</div>
</body>
</html>
我的问题是应用程序显然没有读取放置在文件夹 WebContent/js 中的 js/index.js 文件(放置在 WebContent/css 中的 css 文件可以正常读取)。当我将一些 javascript/jquery 代码直接放在 JSP 页面中时(如问题 Browser doesn't recognize javascript / jquery code 中显示的代码),它们执行时没有任何问题。
有人能找到这个页面的问题吗?
更新 1
$(document).ready(function(){
setupPopup();
});
function setupPopup() {
$('a').click(function() {
$('#content').load($(this).attr('href'));
$('#container').append('<div id="cover">');
$('#results').fadeIn(500);
popupPosition();
});
$('#close').click(function() {
$('#results').fadeOut(100);
$('#cover').remove();
});
$(window).bind('resize', popupPosition);
}
function popupPosition() {
if(!$("#results").is(':visible')){ return; }
$("#results").css({
left: ($(window).width() - $('#results').width()) / 2,
top: ($(window).width() - $('#results').width()) / 7,
position:'absolute'
});
$('#results').draggable();
}
最终更新
最后,我选择不使用jquery,并用这个替换标题中的代码:
<script>
function handleClick(url){
document.getElementById("results").style.display = 'block';
document.getElementById("content").innerHTML='<object type="text/html" data="'+url+'" ></object>';
}
function cleanDiv() {
document.getElementById("results").style.display = 'none';
document.getElementById("content").innerHTML=' ';
}
</script>
每个链接都有这种格式:
<a href="#" onclick="handleClick('listagem_evento.html')" class="icon evento">Eventos</a>
我的弹出窗口的 html 代码得到这个表单:
<section class="about" id="results" style="left: 183px; top: 111px;" onMouseDown="dragStart(event, 'results');">
<div align="right"><a href="#" class="classname" onclick="cleanDiv()">X</a></div>
<div id="content" align="center"></div>
</section>
与方style="left: 183px; top: 111px;" onMouseDown="dragStart(event, 'results');" 负责在屏幕上移动弹出窗口(见问题how to drag and drop a <div> across the page)
【问题讨论】:
-
您有一个
js/index.js... 的相对文件路径,因此它将相对于包含 js 包含的页面的位置进行加载。如果您使用 Fiddler2 或其他工具查看流量,您将收到该文件的 404 错误。 -
如果您使用的是 Chrome 或 Firefox(或 IE 9+),浏览器中的开发工具有一个网络面板,它会显示浏览器加载文件时出现的错误。铬:developers.google.com/chrome-developer-tools/docs/… 火狐:developer.mozilla.org/en-US/docs/Tools/Network_Monitor IE:blogs.msdn.com/b/ie/archive/2010/04/22/…
-
我使用 Firefox 的网络监视器查看文件加载过程中可能出现的任何错误,并且我可以验证所有文件都正确加载,包括 index.js。通过这种方式,我无法弄清楚为什么代码不起作用(在问题中添加了 index.js 的内容)。
-
您能否将屏幕截图链接到 Firefox 的网络监视器结果?
-
这是截图 -> imgur.com/77VDQvP
标签: javascript jquery html jsp