[英]Hide div on click from next page
I want to hide a div on the next page on the click of a button. 我想在单击按钮时在下一页上隐藏div。 Meaning, people will click a button and go to the next page and on the next one I want to apply a '.hide()' with jquery or a 'display: none' for one div. 意思是,人们将单击一个按钮并转到下一页,在下一页上,我要对一个div应用带有jQuery的“ .hide()”或“ display:none”。 What would be the best way I can do this? 我能做到的最好方法是什么? I know how to do this when they're on the same page and with the click of a button, but not if you click the button, go to the next page and then hide something from there. 我知道当他们在同一页面上并单击一个按钮时如何执行此操作,但是如果您单击该按钮,则转到下一页然后从那里隐藏一些内容。
Help! 救命! And thank you!! 谢谢!!
I've tried the sessionStorage but I don't know if I'm applying it correctly. 我已经尝试了sessionStorage,但是我不知道我是否正确应用了它。 The button is from a form and when they click Sign up and it would redirect to another page, the I want one div to be hidden only if the button from the past webpage is clicked. 该按钮来自表单,当他们单击“注册”并将其重定向到另一页面时,仅当单击过去网页中的按钮时,我希望一个div隐藏。 If not the div should be there. 如果没有,div应该在那儿。
Button from page 页面上的按钮
<button id='sign-up-but' class='submit' type="submit" onclick="hiddenInfo()">Sign Up</button>
Form I want to hide - Shown on next page after Sign up button is clicked 我要隐藏的表单-单击“注册”按钮后显示在下一页
<div id="missing-information" class="card"> Form </div>
I want 'missing-information' disappear after 'sign-up-but' is clicked and redirected to next page. 我希望单击“ sign-up-but”后将“ missing-information”消失并重定向到下一页。
If I understand your question correctly, then you could use the LocalStorage
Web API combined jQuery to achieve this - please see the comments in the code snippet below: 如果我正确理解了您的问题,则可以使用结合LocalStorage
Web API的 jQuery实现此目的-请参阅下面的代码片段中的注释:
Javascript: Javascript:
// Requires jQuery, include this script in both pages of website
$(function() {
// When sign-up-but clicked, use localStorage to remember to hide
// the missing-information div by using localStorage.setItem()
$('#sign-up-but').click(function() {
localStorage.setItem('missing-information', 'hide');
});
// When the page is loaded and this script is run, check if
// "missing-information" has "hide" in localStorage
if(localStorage.getItem('missing-information') === 'hide') {
// If "hide" is in local storage, then hide() any element with
// id of missing-information that exists on the page
$('#missing-information').hide();
}
});
HTML: HTML:
<!-- Remove onclick handler -->
<button id='sign-up-but' class='submit' type="submit">Sign Up</button>
<div id="missing-information" class="card">
Missing information
</div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.