我正在使用 Framework7 开发一个 Web 应用程序。我想在单击链接时移至另一个页面,导出变量。
在index.php中我有这个:
<head>
<script type="text/javascript">
function myFunc(xyz) {
localStorage.setItem("variable", xyz);
}
</script>
</head>
<body>
<?php
foreach( [...] ) {
[...] // something not important
print('
<a onclick="myFunc('.$myVar.')" href="anotherPage.php">'.$myVar.'</a>
');
}
?>
</body>
在anotherPage.php中我有这个:
<p id="example"></p>
<script>
document.getElementById("example").innerHTML = localStorage.getItem("variable");
</script>
我不知道为什么它不起作用...你能帮助我吗?
附注: 我发现这可能有用:Ajax pages | Framework7
非常感谢!
最佳答案
F7是一个SPA框架,它加载新页面不需要JS。 您应该在 index.php
中添加 pageInit 回调<a href="anotherPage.php?variable=xyz"/>
<script type="text/javascript">
myApp.onPageInit('another-page', function (page) {
// here is the variable
console.log(page.query.variable);
});
</script>
anotherPage.php 应采用如下格式
<div class="navbar">
</div>
<div class="page" data-page="another-page">
...
</div>
还有另一种通过“查询”对象传递变量的方法。 https://framework7.io/docs/router-api.html
mainView.router.load({
url: "anotherPage.php",
query: {
variable: 'xyz',
...
}
});
关于javascript - 如何在 Framework7 中移动到另一个页面(导出变量)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40386835/