I have a simple page with a table and i want it to be sortable, so i got jquery and tablesorter. Heres my page:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="/css/base.css"/>
<script src="/javascript/jquery-1.4.3.js" type="text/javascript"></script>
<script src="/javascript/jquery.tablesorter.js" type="text/javascript"></script>
<title>JSP Page</title>
<script type="text/javascript">
$(document).ready(function() {
$("#tabela").tableSorter();
});
</script>
</head>
<body>
<p>
<label><h3>Lista de Personagens</h3></label>
</p>
<p>
<a href="inserir.htm">Novo Personagem</a>
</p>
<table id="tabela" border="1" cellspacing="0" cellpadding="0">
<tr>
<th>Codigo</th>
<th>Nome</th>
<th>Classe</th>
<th colspan="3">Opções</th>
</tr>
<c:forEach items="${lista}" var="p">
<tr>
<td>${p.id}</td>
<td>${p.nome}</td>
<td>${p.classe}</td>
<form id="formAlterar${p.id}" method="get" action="alterar.htm">
<td>
<input type="hidden" name="id" value="${p.id}" />
<a href="#" onclick="document.getElementById('formAlterar${p.id}').submit()">Alterar</a>
</td>
</form>
<form id="formConsultar${p.id}" method="post" action="consultar.htm">
<td>
<input type="hidden" name="id" value="${p.id}" />
<a href="#" onclick="document.getElementById('formConsultar${p.id}').submit()">Consultar</a>
</td>
</form>
<form id="formExcluir${p.id}" method="post" action="excluir.htm">
<td>
<input type="hidden" name="id" value="${p.id}" />
<a href="#" onclick="document.getElementById('formExcluir${p.id}').submit()">Excluir</a>
</td>
</form>
</tr>
</c:forEach>
</table>
I have the javascript folder at the same level as WEB-INF. I think i pointed to the right place. but when i load the page, nothing happens, the table statys fixed, no sorting. Can it be related to the fact im using Spring MVC and the mapping makes it point to the wrong location? Heres my mapped method:
@RequestMapping("/personagem/index.htm")
public ModelAndView listar(@RequestParam(value = "mensagem", required = false) String mensagem) {
ArrayList<Personagem> lista = getPersonagemService().listarTodos();
return new ModelAndView("listar", "lista", lista);
}
Edit: The generated HTML code (it's a bit long, so i cut off the repeating part):
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="/css/base.css"/>
<script src="/javascript/jquery-1.4.3.js" type="text/javascript"></script>
<script src="/javascript/jquery.tablesorter.js" type="text/javascript"></script>
<title>JSP Page</title>
<script type="text/javascript">
$(document).ready(fu开发者_如何学Gonction() {
$("#tabela").tableSorter();
});
</script>
</head>
<body>
<p>
<label><h3>Lista de Personagens</h3></label>
</p>
<p>
<a href="inserir.htm">Novo Personagem</a>
</p>
<table id="tabela" border="1" cellspacing="0" cellpadding="0">
<tr>
<th align="center">Nome</th>
<th align="center">Classe</th>
<th width="250" colspan="3">Opções</th>
</tr>
<tr>
<td width="150" align="center">Melys</td>
<td width="150" align="center">Priest</td>
<form id="formAlterar4" method="get" action="alterar.htm">
<td align="center">
<input type="hidden" name="id" value="4" />
<a href="#" onclick="document.getElementById('formAlterar4').submit()">Alterar</a>
</td>
</form>
<form id="formConsultar4" method="post" action="consultar.htm">
<td align="center">
<input type="hidden" name="id" value="4" />
<a href="#" onclick="document.getElementById('formConsultar4').submit()">Consultar</a>
</td>
</form>
<form id="formExcluir4" method="post" action="excluir.htm">
<td align="center">
<input type="hidden" name="id" value="4" />
<a href="#" onclick="document.getElementById('formExcluir4').submit()">Excluir</a>
</td>
</form>
</tr>
Have you confirmed that the following resources are served properly? (e.g., they aren't 404, they are the correct content type, etc.)
- /css/base.css
- /javascript/jquery-1.4.3.js
- /javascript/jquery.tablesorter.js
If so, have you used something like the Firefox Error Console to ensure that there are no JavaScript errors in your code?
Also, why are you embedding forms in your table that appear to just link to a page with an id? In other words, why not just link to the page?
精彩评论