所以,快速提问 - 我检查是否在 html 文档上单击了一个复选框,然后当用户单击继续按钮时,它会将他们带到下一页,该页面将根据是否单击该按钮来执行操作复选框被选中。最简单的方法是什么?
在 index.html 文件(主页)中我有
if ($("#checkArray").is(":checked")) {
console.log("permission granted");
} else {
console.log("No permissions granted");
}
window.location='/auth/facebook';
检查复选框是否被标记。然后它转到下一个 html 文档 (confirmation.html) 以获取 facebook 的授权 在这里,如果复选框被选中 (true),我想调用一个函数。
求助!谢谢!!
最佳答案
您可以使用cookies
或sessionStorage
。
SessionStorage 示例:
if ($("#checkArray").is(":checked")) {
window.sessionStorage.setItem('checked', true);
} else {
window.sessionStorage.setItem('checked', false);
}
window.location='/auth/facebook';
在其他页面上:
var checked = window.sessionStorage.getItem('checked');
SessionStorage 适用于现代浏览器,因此如果您需要支持 IE8 等旧浏览器,则应使用 cookie。您可以在此处阅读有关 cookie 的更多信息:http://www.w3schools.com/js/js_cookies.asp .
关于javascript - 如何在另一个html中调用函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25233940/