Show Hide div if, if statement is true

后端 未结 7 437
情歌与酒
情歌与酒 2020-12-08 15:46

My code works to a point. What I want is that when this if statement is false, the

doesn\'t show



        
相关标签:
7条回答
  • 2020-12-08 16:23

    from php you can invoke jquery like this but my 2nd method is much cleaner and better for php

    if($switchView) :?>
     <script>$('.container').hide();</script>
     <script>$('.confirm').show();</script>
    <?php endif;
    

    another way is to initiate your class and dynamically invoke the condition like this

    $registerForm ='block'; 
    

    then in your html use this

    <div class="col" style="display: <?= $registerForm?>">
    

    now you can play with the view with if and else easily without having a messed code example

    if($condition)  registerForm = 'none'; 
    

    Make sure you use 'block' to show and 'none' to hide. This is far the easiest way with php

    0 讨论(0)
  • 2020-12-08 16:31

    You can use css or js for hiding a div. In else statement you can write it as:

    else{
    ?>
    <style type="text/css">#divId{
    display:none;
    }</style>
    <?php
    }
    

    Or in jQuery

    else{
    ?>
    <script type="text/javascript">$('#divId').hide()</script>
    <?php
    }
    

    Or in javascript

    else{
    ?>
    <script type="text/javascript">document.getElementById('divId').style.display = 'none';</script>
    <?php
    }
    
    0 讨论(0)
  • 2020-12-08 16:33

    Use show/hide method as below

    $("div").show();//To Show
    
    $("div").hide();//To Hide
    
    0 讨论(0)
  • 2020-12-08 16:34
    <?php
    $divStyle=''; // show div
    
    // add condition
    if($variable == '1'){
      $divStyle='style="display:none;"'; //hide div
    }
    
    print'<div '.$divStyle.'>Div to hide</div>';
    ?>
    
    0 讨论(0)
  • 2020-12-08 16:37

    A fresh look at this(possibly)
    in your php:

    else{
          $hidemydiv = "hide";
    }
    

    And then later in your html code:

    <div class='<?php echo $hidemydiv ?>' > maybe show or hide this</div>
    

    in this way your php remains quite clean

    0 讨论(0)
  • 2020-12-08 16:41

    Probably the easiest to hide a div and show a div in PHP based on a variables and the operator.

    <?php 
    $query3 = mysql_query($query3);
    $numrows = mysql_num_rows($query3);
    ?>
    <html>
    <?php if($numrows > null){ ?>
         no meow :-(
    <?php } ?>
    
    <?php if($numrows < null){ ?>
         lots of meow
    <?php } ?>
    </html>
    

    Here is my original code before adding your requirements:

    <?php 
    $address = 'meow';
    ?>
    <?php if($address == null){ ?>
         no meow :-(
    <?php } ?>
    
    <?php if($address != null){ ?>
         lots of meow
    <?php } ?>
    
    0 讨论(0)
提交回复
热议问题