采纳追加赏 2022-08-30 11:03 采纳率: 35.3%
浏览 132
已结题

判断浏览器只显示一次js

页面上.box只显示一次,后面刷新不显示。
浏览器新建窗口一次窗口可以打开,再次刷新就不显示。


<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <title> 浏览器窗口只打开一次 </title>
    <script src="https://code.jquery.com/jquery-1.7.2.js"></script>
</head>
<body>

<style type="text/css">
.box{width:100px;height:100px;margin:100px auto;background:#ff6600;}
</style>

<div class="box"></div>


<script>

</script>  

</body>
</html>

  • 写回答

6条回答 默认 最新

  • Roc-xb 后端领域优质创作者 2022-08-30 12:27
    关注
    
     <!doctype html>
     <html lang="en">
    
     <head>
         <meta charset="UTF-8" />
         <meta name="viewport" content="width=device-width, initial-scale=1.0">
         <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
         <title> 浏览器窗口只打开一次 </title>
         <script src="https://code.jquery.com/jquery-1.7.2.js"></script>
     </head>
    
     <body>
    
         <style type="text/css">
             .box {
                 width: 100px;
                 height: 100px;
                 margin: 100px auto;
                 background: #ff6600;
             }
         </style>
    
         <div class="box"></div>
    
    
         <script>
             let hasBox = sessionStorage.getItem('hasBox')
             if (!hasBox) {
                 $('.box').show();
                 sessionStorage.setItem('hasBox', true)
             } else {
                 $(".box").remove();
             }
         </script>
    
     </body>
    
     </html>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(5条)

报告相同问题?

问题事件

  • 系统已结题 9月14日
  • 已采纳回答 9月6日
  • 创建了问题 8月30日

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog