无法使用if条件将会话存储设置项的值传递到ready函数中以执行其他操作:
<script type="text/javascript">
function Re() {
sessionStorage.setItem("hasClick", true);
window.location.replace("http://127.0.0.1:5000/test");
}
function ready(callback) {
if (document.readyState != 'loading') callback();
else if (document.addEventListener) document.addEventListener('DOMContentLoaded', callback);
else document.attachEvent('onreadystatechange', function () {
if (document.readyState == 'complete') callback();
});
}
ready(function () {
console.log("It worked!");
var hasClick = localStorage.getItem("hasClick");
if (hasClick == true) {
var labels = document.getElementsByTagName('label');
labels[4].style.cssText = 'color:blue; font-size:22px;';
}
});
</script>
var hasClick = localStorage.getItem("hasClick");
值未传递给hasClick