假设我们在数据表中有n页,并且该数据表的一列具有通过发送新请求来打开新页面(仪表板)的链接。
我们必须在此新页面(仪表盘)上添加后退按钮,这样才能将我们移至数据表的最后打开的页面。
我们像这样应用后退按钮-
<button style="postion:fixed;" class="pull-right" onclick="window.history.go(-1); ">Back</button>
但是此按钮会将我们发送到数据表的第一页,而不是打开链接的第n页。
最佳答案
您可以将页码保存在第一个URL的哈希中,如下所示:
<a href="secondPage.html" onClick="window.location.hash = encodeURIComponent(JSON.stringify({page: table.current_page_in_table}));">link</a>
然后,在加载页面后,检查您是否具有哈希,如果有,请读取页码并更新表以转到该页面:
<script type="text/javascript">
function goToRightPage() {
if (window.location.hash) {
// Read the hash string omitting the # prefix
var hashJson = window.location.hash.substring(1);
// Restore the deserialized data to memory
myData = JSON.parse(decodeURIComponent(hashJson));
datatable.goToPage(myData.page);
}
}
window.onload = goToRightPage;
</script>
关于jquery - 后退按钮可移动数据表的第n页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33796135/