【问题标题】:When radio button is checked redirect to second page and hide certain html element in the second page by checking if radio button was clicked检查单选按钮重定向到第二页并通过检查单击单键按钮是否单击了第二页中的某些HTML元素
【发布时间】:2016-01-09 02:12:06
【问题描述】:

这是我在 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在哪里??
  • 意味着你要加载第二个,html 包含第二个 div?还是第一页包含第二个 div?
  • @SandipanGuha 在我的第二页中我有以下代码
    Second div

标签: javascript jquery html ajax local-storage


【解决方案1】:

在第一个和第二个 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>

【讨论】:

  • 感谢您的快速回复。我已经尝试过使用上面的代码。它没有按预期工作。在 j 查询中,是否可以使用 ajax 方法。请建议。
  • 您是否在目录中创建了 second.html 页面?并添加了显示div?我做到了.. 使用 firefox 作为您的浏览器。
  • 是的,哥们我也很累,因为 chrome 不支持加载它需要本地主机,所以我在 firefox 中尝试了:(
  • 所以这就是我问有没有办法使用ajax方法的原因
  • 第二页的这
    Second div
    行,而不是创建整个页面,我只是放置了相关行,因此当用户从第一页单击继续教育时此 div 将隐藏的第二页
猜你喜欢
  • 1970-01-01
  • 2014-04-09
  • 2014-07-01
  • 1970-01-01
  • 2023-03-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多