POST后徒步旅行DIV


Hidding a DIV after POST

在用window.location.assign发布变量后,我试图隐藏DIV。如果选择了DIV中的checkbox,则会发布变量。

我的代码在下面。

$(document).on("change", ".checkbox", function () {
   var db = $(this).val();
   window.sessionStorage.setItem("db", db);
   window.location.assign("index.php?db=" + db);
   document.getElementById('dbdisplay').style.display='none';
});

我遇到的问题是DIV只是在通过.assign刷新页面之前暂时隐藏。我尝试使用location.href,但这不是通过db变量发布的,所以我的PHP代码不会运行。我该怎么解决这个问题??

一个与您一直在尝试的相同的替代解决方案。

CSS:

#dbdisplay { display: none; }

JS:

//Check if there is querystring matching db=somevalue
//and if "no", display the div
if (!location.search.match(/db=[^&#]+/i)) {
    $("#dbdisplay").show();
}
$(document).on("change", ".checkbox", function () {
   var db = $(this).val();
   window.sessionStorage.setItem("db", db);
   window.location.assign("index.php?db=" + db);
   $("#dbdisplay").hide();
});