【问题标题】:Hide a div in while user session exists在用户会话存在时隐藏 div
【发布时间】:2014-03-02 14:32:05
【问题描述】:

我有这个问题:我不知道如何隐藏会话开始时出现的 div。所以我有一个用于关闭的 X 按钮,当页面刷新时,div 再次出现!但我不想停止会话。 我的代码:

<div id="got-points" style="display:<?php echo (isset($customer) && !empty($customer) && isset($customer['customer']) && !empty($customer['customer'])) ? 'block' : 'none'; ?>"> // Checks if session is active
<div class="got-points-bg" style="display: visible;">
    <div class="got-points-box">
        <img class="got-points-close" src="<?php echo base_url();?>static/images/i8.png" /> //Close Button

           My text here

    </div>
  </div>
</div>

还有js

  <script>
$(document).ready(
    function() {
        $(".got-points-close").click(function() {
            $(".got-points-bg").hide("fast");
        });
    });
  </script>

【问题讨论】:

    标签: php jquery session


    【解决方案1】:

    如果它在刷新,那很容易;只需在 PHP 会话中执行;像这样:

    HTML:

    <div id="got-points" style="display:<?php echo (isset($customer) && !empty($customer) && isset($customer['customer']) && !empty($customer['customer']) && empty($_SESSION['first_load'])) ? 'block' : 'none'; ?>"> // Checks if session is active
    <div class="got-points-bg" style="display: visible;">
        <div class="got-points-box">
            <img class="got-points-close" src="<?php echo base_url();?>static/images/i8.png" /> //Close Button
    
               My text here
    
        </div>
      </div>
    </div>
    

    在那之前在你的 PHP 中(比如登录/会话开始)——这显然需要大量的编辑,因为你没有包含你的 PHP 我不能很好地猜测它,但这应该提供一个起点:

    <?php
        //load user check pseudo code
        if !empty($_SESSION[user]) and whatever other checks... {
            $_SESSION['first_load'] = False; //important line number 2
        }
        //login pseudo code to demonstrate placement within your code
        if user & pass = valid {
            $_SESSION['first_load'] = True; //important line number one
        }
    

    假设您想要 div 输出但不显示在后续加载中。

    【讨论】:

      【解决方案2】:

      有趣的问题,这样的事情怎么样?

      <?php
      
      if(isset($_SESSION['variable'])){
          sleep(3); /* Duration(in seconds) div is displayed for */
          echo
          "<script>
              $( document ).ready(function() {
                  $(".got-points-bg").hide("fast");
              });
         </script>";
      }
      
      ?>
      

      【讨论】:

        【解决方案3】:

        试试这个

        <?php error_reporting(0); session_start(); if(empty($_SESSION['user'])) echo "<div id='togglediv'> My text here </div>"; ?>    
        

        希望它会起作用

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2015-12-19
          • 1970-01-01
          • 2023-03-08
          • 2016-04-10
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多