目前我在所有页面上都遇到问题。该页面包含一个带有提交按钮的表单和一个包含按钮的表格。问题是每当我单击表格
中的编辑按钮时,css
和 javascript
消失了。
这是 jascript 代码
<script type="text/javascript">
$(document).ready(function() {
var table = $('#datatable').dataTable();
var tableTools = new $.fn.dataTable.TableTools(table, {
'aButtons' : [ ],
'sSwfPath' : 'js/copy_csv_xls_pdf.swf'
});
$(tableTools.fnContainer()).insertBefore('#datatable_wrapper');
});
</script>
表格
<table id="datatable" class="hover" >
<thead>
<tr>
<th width="80">Poll ID</th>
<th width="120">Poll Name</th>
<th width="120">Poll Description</th>
<th width="120">poll publisher</th>
<th width="60">Edit</th>
<th width="60">Delete</th>
<th width="60">Voter</th>
<th width="60">Afficher courbe</th>
</tr>
</thead>
<tfoot>
<tr>
<th width="80">Poll ID</th>
<th width="120">Poll Name</th>
<th width="120">Poll Description</th>
<th width="120">poll publisher</th>
<th width="60">Edit</th>
<th width="60">Delete</th>
<th width="60">Voter</th>
<th width="60">Afficher Courbe</th>
</tr>
</tfoot>
<c:forEach items="${listpolls}" var="poll">
<tbody>
<tr>
<td>${poll.id_poll}</td>
<td>${poll.titre}</td>
<td>${poll.description}</td>
<td>${poll.emp_login}</td>
<td><a href="<c:url value='/poll/edit/${poll.id_poll}' />">Edit</a></td>
<td><a href="<c:url value='/poll/remove/${poll.id_poll}' />">Delete</a></td>
<td><a href="<c:url value='/poll/voter/${poll.id_poll}' />">Vote</a></td>
<td><a href="<c:url value='/sa/${poll.id_poll}' />">Afficher courbe</a></td>
</tr>
</c:forEach>
</tbody>
</table>
这是我点击编辑之前的表格图片。
现在
如您所见,css 和 javascipt 代码都消失了。
我在这里做错了什么?非常感谢任何帮助。
最佳答案
问题是 /poll/edit/...
等等在链接的href 中。即使重定向,浏览器仍然认为您位于不同的目录中,样式和脚本的相对路径将不起作用。
指定页面上所有链接的基目录:
<base href="http://www.domain.com/somebasedir/" />
然后不管重定向如何,例如这个样式表:
<link rel="stylesheet" type="text/css" href="path/style.css" />
应始终在以下位置查找:
/somebasedir/path/style.css
关于javascript - 点击按钮后 CSS 和 javascript 就消失了,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38216898/