gpt4 book ai didi

javascript - 当选中单选按钮时,重定向到第二页并通过检查是否单击单选按钮来隐藏第二页中的某些 html 元素

转载 作者:行者123 更新时间:2023-11-27 23:47:07 25 4
gpt4 key购买 nike

这是我的第一个 html 页面数据

<div class="edu">
<input type="radio" name="edu" class="ug" value="ug" checked="checked">
<label class="radio-label">Undergraduate</label>
<input type="radio" name="edu" value="pg" class="pg">
<label class="radio-label">Postgraduate</label>
<input type="radio" name="edu" value="cu" class="cu">
<label class="radio-label">Continuing Education</label>
</div>

这是我的第二页内容:

<div class="display"> 
sample text
</div>

当客户从第一页选中“继续教育”单选按钮时,第二页将被重定向/在新窗口/新选项卡中打开。在第二页中,我想检查是否在第一页中单击了“继续教育”按钮。如果,则隐藏第二页中的“.display”div。

我想使用 Jquery,以及任何其他需要的东西。请指导我,因为我是新人。谢谢。

最佳答案

从第一个和第二个 html 文件顶部加载 jQuery:

<script src="https://code.jquery.com/jquery-1.10.2.js"></script>

在第一页底部添加此 jQuery 代码:

 <script> 
$(document).ready(function(){
$(".cu").on("click", function(){
localStorage.setItem("cu","clicked");
//var key = localStorage.key(0);
//alert(key);
window.open('second.html', '_blank');
});
});
</script>

然后在第二个 html 页面的底部添加此代码。这将检查 localStorage 值是否设置为“cu”,您可以了解是否单击了“继续教育”。如果,那么它将隐藏 ".display" div。

 <script>
$(document).ready(function(){
if(localStorage.key(0) == "cu")
{
//$(".display").fadeOut(500) ;
$(".display").hide(500) ;
//alert(localStorage.key(0));
localStorage.clear();
localStorage.removeItem("cu");
}
});
</script>

关于javascript - 当选中单选按钮时,重定向到第二页并通过检查是否单击单选按钮来隐藏第二页中的某些 html 元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33066886/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com