【问题标题】:MODAL: Show and hide a div inside a ModalMODAL:在 Modal 中显示和隐藏 div
【发布时间】:2019-10-29 08:36:41
【问题描述】:

点击提交按钮后,如何在 Modal 中显示和隐藏 div(内容)?

第一: 这张照片My Search Div.Jpg - 就是你要输入ID号的div标签。

第二个: Preferred Output.Jpg - 单击提交按钮后,现在对与给定 ID 号匹配的数据库运行检查查询。那么所有文本框的值都必须来自数据库。

问题:我无法使用submit button 来显示和隐藏div 使用if (!isset($_POST['Search_ID']))。单击提交后,模式关闭并重新加载页面。

请给出任何解决方案,包括它的 php、javascript 或 jquery 或 css?

<div class="modal-body">
  <h5 style="font-family: Century Gothic">SEARCH ID NO.
    <form method="Post">
      <div class="form-group form-md-line-input has-danger">
        <div class="input-icon">
          <input type="text" class="form-control" name="Search_ID" style="padding-left: 5px" autocomplete="off">
          <label style="font-weight: bolder; font-size: 11px; font-family: Arial Narrow ">INSERT ID NUMBER OF THE EMPLOYEE YOU WISH TO UPDATE.</label>
          <span class="help-block" style="font-size: 10px; text-align: right;">Update Form will show when successfully entered ID No.</span>
          <!--<i class="fa fa-info"></i>-->
        </div>

      </div>
    </form>
  </h5>
  <?php 
if (!isset($_POST['Search_ID'])) {                                                    
?>

  <div class="row" id="Hide_Div">
    <br/>
    <div class="col-md-4">
      <div class="form-group form-md-line-input has-danger">
        <div class="input-icon">
          <input type="text" class="form-control" name="id_no" style="padding-left: 10px">
          <label style="font-weight: bolder; font-size: 11px; font-family: Arial Narrow ">EMPLOYEE ID NO.</label>
          <span class="help-block" style="font-size: 10px">Insert Employee ID No...</span>
        </div>
      </div>
    </div>

    <div class="col-md-8">
      <div class="form-group">
        <label style="font-weight: bolder; font-size: 11px; font-family: Arial Narrow; color: grey">EMPLOYEE STATUS</label>
        <div class="kt-radio-inline">
          <label class="kt-radio">
                                                                                <input type="radio" name="radio6" value="Active"> <font color="green">Active</font>
                                                                                <span>&nbsp</span>
                                                                            </label>
          <label class="kt-radio">
                                                                                <input type="radio" name="radio6" value="Non-Active" checked> <font color="orange">Non-Active</font>
                                                                                <span>&nbsp</span>
                                                                            </label>
          <label class="kt-radio">
                                                                                <input type="radio" name="radio6" value="Disabled"> Disabled
                                                                                <span>&nbsp</span>
                                                                            </label>
        </div>

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

  <div class="row">
    <div class="col-md-4">
      <div class="form-group form-md-line-input has-danger" style=" margin-bottom: 15px">
        <div class="input-icon">
          <input type="text" class="form-control" name="lname" required style="padding-left: 10px">
          <label for="form_control_1" style="font-weight: bolder; font-size: 11px">LAST NAME</label>
          <span class="help-block" style="font-size: 10px">Insert Last Name...</span>
        </div>
      </div>
    </div>

    <div class="col-md-4">
      <div class="form-group form-md-line-input has-danger" style=" margin-bottom: 15px">
        <div class="input-icon">
          <input type="text" class="form-control" name="firname" required style="padding-left: 5px">
          <label for="form_control_1" style="font-weight: bolder; font-size: 11px">FIRST NAME</label>
          <span class="help-block" style="font-size: 10px">Insert First Name...</span>
        </div>
      </div>
    </div>

    <div class="col-md-3">
      <div class="form-group form-md-line-input has-danger" style=" margin-bottom: 15px">
        <div class="input-icon">
          <input type="text" class="form-control" name="mname" style="padding-left: 5px; ">
          <label for="form_control_1" style="font-weight: bolder; font-size: 11px">INITIAL</label>
          <span class="help-block" style="font-size: 10px">Insert Initial...</span>
        </div>
      </div>
    </div>
  </div>

  <div class="row">
    <div class="col-md-4">
      <div class="form-group form-md-line-input has-danger">
        <div class="input-icon">
          <input type="text" class="form-control" name="department" required style="padding-left: 10px">
          <label style="font-weight: bolder; font-size: 11px; font-family: Arial Narrow ">DEPARTMENT</label>
          <span class="help-block" style="font-size: 10px">Insert Department Name...</span>
        </div>
      </div>
    </div>

    <div class="col-md-8">
      <div class="form-group form-md-line-input has-danger">
        <div class="input-icon">
          <input type="text" class="form-control" name="Jo_title" required style="padding-left: 5px">
          <label style="font-weight: bolder; font-size: 11px; font-family: Arial Narrow ">JOB TITLE</label>
          <span class="help-block" style="font-size: 10px">Insert your job title...</span>
        </div>
      </div>
    </div>
  </div>

  <div class="note note-danger">
    <h5 style="font-family: Century Gothic"> More Information Here:
      <div class="form-group form-md-line-input has-danger">
        <div class="input-icon">
          <input type="text" class="form-control" name="Mor_Desc" style="padding-left: 5px">
          <label style="font-weight: bolder; font-size: 11px; font-family: Arial Narrow ">ADDITIONAL INFORMATION ABOUT THE EMPLOYEE</label>
          <span class="help-block" style="font-size: 10px">Insert Short Description...</span>
          <!--<i class="fa fa-info"></i>-->
        </div>
      </div>
    </h5>
  </div>



  <?php }else{ ?>


  <?php }
                                                        ?>




</div>

【问题讨论】:

  • Ajax 会解决你的问题。
  • @XraySensei 你能告诉我怎么做吗?
  • 如果你能把你的代码sn-p放在这里,而不是张贴图片会很好。
  • 是的,请放一些代码
  • @COONH 当然我们可以告诉你如何。向我们展示您的代码,我们将为您提供帮助。

标签: javascript php jquery css


【解决方案1】:

到目前为止,我使用 2 种不同的模式解决了我自己的问题。 我使用了$_GET[] 方法和if else 语句结合jquery 事件。

过滤代码事件

 <!--START EDIT FILTER CODE-->
 <?php
    include ("connection/conn.php");

    if (isset($_GET['btn_search'])){

    $id = $_GET['Search_ID'];

    $query = "SELECT * FROM tbl_employee WHERE emp_id_no = '$id'";
    $result = mysqli_query($conn, $query);
    $row = mysqli_fetch_array($result);


    if ($row > 0){
    ?>
         <div style="display: none;">
             <input type="button" name="edit" value="Edit" id="<?php echo $row["emp_id_no"]; ?>" class="btn btn-info btn-xs edit_data" />
         </div>
     <?php
         }

         if ($id != "") { ?>
            <script>
                $( document ).ready(function() {
                     $('#add_data_modal').modal('show');

                     });
            </script>

      <?php

            }
         }

       ?>

搜索模式事件 (Sample Photo)

<!--SEARCH Modal-->
                                    <div id="modal_edit" class="modal fade" tabindex="-1" data-backdrop="static" data-keyboard="false">
                                            <div class="modal-dialog">
                                                <div class="modal-content">
                                                    <div class="modal-header" style="background-color: #ad3a1a">
                                                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true" onclick="location.href='employees.php'"></button>
                                                        <h4 class="modal-title"><font style="font-family: ARIAL; font-weight: bold;"> EMPLOYEE: RECORD EDITOR </font></h4>
                                                    </div>
                                                    <div class="be_hidden_attribute">

                                                    <div class="modal-body">
                                                        <h5 style="font-family: Century Gothic">SEARCH ID NO. 
                                                        <form method="GET" > 
                                                            <div class="form-group form-md-line-input has-danger">

                                                                    <div class="input-icon">
                                                                        <input type="text" class="form-control" name="Search_ID" id="Search_ID"   style="padding-left: 5px; font-family: ARIAL; font-weight: bolder; font-size: 25px" autocomplete="off" >
                                                                        <label style="font-weight: bolder; font-size: 11px; font-family: Arial Narrow ">INSERT ID NUMBER OF THE EMPLOYEE YOU WISH TO UPDATE.</label>
                                                                        <span class="help-block" style="font-size: 10px; text-align: right;">Update Form will show when successfully entered ID No.</span>
                                                                        <!--<i class="fa fa-info"></i>-->
                                                                    </div>

                                                                    <p class="space_created">
                                                                        <!--
                                                                            <input type="button" value="Search" id="search" />
                                                                            <a href="#add_data_modal" data-toggle="modal" data-dismiss="modal" name="GG"> 
                                                                                Launch Modal Two
                                                                            </a>
                                                                        -->
                                                                            <input type="submit" name="btn_search" value="SEARCH" class="btn btn-info" id="btn_search_id"> 

                                                                    </p>

                                                            </div>
                                                        </form>
                                                        </h5>

                                                    </div>


                                                    <div class="modal-footer">
                                                    <!--
                                                        <button type="button" data-dismiss="modal" class="btn dark btn-outline">Cancel</button>
                                                        <input type="submit" name="btnSubmit" value="Continue Task"  class="btn green"> 
                                                    -->
                                                    </div>




                                                    </div>
                                                </div>
                                            </div>
                                    </div>
<!--End Modal-->

模态:显示搜索 ID 的数据 (sample)

                                    <div id="add_data_modal" class="modal fade" tabindex="-1" data-backdrop="static" data-keyboard="false">
                                            <div class="modal-dialog">
                                                <div class="modal-content">


                                                    <?php

                                                     $Dim_ID_REF = $row["emp_id_no"];
                                                     $Dim_Emp_Lname = $row["emp_lname"];
                                                     $Dim_Emp_Fname = $row["emp_fname"];
                                                     $Dim_Emp_Mname = $row["emp_mname"];
                                                     $Dim_Emp_Job = $row["emp_job_name"];
                                                     $Dim_Emp_Dep = $row["emp_dep"];
                                                     $Dim_Emp_Stat = $row["emp_status"];
                                                     $Dim_Emp_Info = $row["emp_add_info"];


                                                     ?>







                                                    <div class="modal-header" style="background-color: #17ad3f">
                                                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true" onclick="location.href='employees.php'"></button>
                                                        <h4 class="modal-title"><font style="font-family: ARIAL; font-weight: bold;"> EMPLOYEE UPDATE FORM </font></h4>
                                                    </div>



                                                    <div class="modal-body">

                                                    <?php 

                                                    if ($Dim_ID_REF == "") { 
                                                    ?>

                                                        <div class="row" >
                                                                <div class="note note-danger" style="margin: 20px">
                                                                    <h2 style="font-family: Century Gothic; ">NO DATA RECORD FOR THIS EMPLOYEE. </h2>
                                                                </div>
                                                        </div>

                                                    <div class="modal-footer">
                                                        <button type="button" data-dismiss="modal" class="btn dark btn-outline" onclick="location.href='employees.php'">Close</button>
                                                        <a href="#modal_edit" data-toggle="modal" data-dismiss="modal" class="btn btn-danger">&#x21BA; Go Back</a>

                                                    </div>    


                                                    <?php 
                                                    }else{
                                                    ?>
                                                    <form method="POST" autocomplete="off">
                                                            <div class="row">

                                                                <br/>
                                                                <div class="col-md-4">
                                                                    <div class="form-group form-md-line-input has-danger">
                                                                        <div class="input-icon">
                                                                            <input type="hidden" class="form-control" name="employee_id" id="employee_id" style="padding-left: 10px;" >
                                                                            <input type="text" class="form-control" name="employee_id_no" id="employee_id_no" style="padding-left: 10px; font-weight: bolder; font-size: 20px; color: crimson"  value="<?php echo $Dim_ID_REF; ?>" disabled>
                                                                            <label style="font-weight: bolder; font-size: 11px; font-family: Arial Narrow ; text-align: center;">EMPLOYEE ID NO. (SEARCH ID)</label>
                                                                            <span class="help-block" style="font-size: 10px">Insert Employee ID No...</span>
                                                                        </div>
                                                                    </div>
                                                                </div>

                                                                 <div class="col-md-8"> 
                                                                    <div class="form-group">
                                                                        <label style="font-weight: bolder; font-size: 11px; font-family: Arial Narrow; color: grey">EMPLOYEE STATUS</label>
                                                                        <div class="kt-radio-inline">
                                                                            <label class="kt-radio">
                                                                                <input type="radio" name="radio6" value="Active"> <font color="green">Active</font>
                                                                                <span>&nbsp</span>
                                                                            </label>
                                                                            <label class="kt-radio">
                                                                                <input type="radio" name="radio6" value="Non-Active" checked> <font color="orange">Non-Active</font>
                                                                                <span>&nbsp</span>
                                                                            </label>
                                                                            <label class="kt-radio">
                                                                                <input type="radio" name="radio6" value="Disabled"> Disabled
                                                                                <span>&nbsp</span>
                                                                            </label>
                                                                        </div>

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

                                                            <div class="row">
                                                                <div class="col-md-4">
                                                                    <div class="form-group form-md-line-input has-danger" style=" margin-bottom: 15px">
                                                                        <div class="input-icon">
                                                                            <input type="text" class="form-control" name="lname" id="lname" required style="padding-left: 10px;font-weight: bolder; font-size: 20px" value="<?php echo $Dim_Emp_Lname; ?>">
                                                                            <label for="form_control_1" style="font-weight: bolder; font-size: 11px">LAST NAME</label>
                                                                            <span class="help-block" style="font-size: 10px">Insert Last Name...</span>
                                                                        </div>
                                                                    </div>
                                                                </div>

                                                                <div class="col-md-4">
                                                                    <div class="form-group form-md-line-input has-danger" style=" margin-bottom: 15px">
                                                                        <div class="input-icon">
                                                                            <input type="text" class="form-control" name="fname" id="fname" required style="padding-left: 5px;font-weight: bolder; font-size: 20px" value="<?php echo $Dim_Emp_Fname; ?>">
                                                                            <label for="form_control_1" style="font-weight: bolder; font-size: 11px">FIRST NAME</label>
                                                                            <span class="help-block" style="font-size: 10px">Insert First Name...</span>
                                                                        </div>
                                                                    </div>
                                                                </div>

                                                                <div class="col-md-3">
                                                                    <div class="form-group form-md-line-input has-danger" style=" margin-bottom: 15px">
                                                                        <div class="input-icon">
                                                                            <input type="text" class="form-control" name="mname" id="mname" style="padding-left: 5px;font-weight: bolder; font-size: 20px " value="<?php echo $Dim_Emp_Mname; ?>">
                                                                            <label for="form_control_1" style="font-weight: bolder; font-size: 11px">INITIAL</label>
                                                                            <span class="help-block" style="font-size: 10px">Insert Initial...</span>
                                                                        </div>
                                                                    </div>
                                                                </div>
                                                            </div>

                                                            <div class="row">
                                                                    <div class="col-md-4">
                                                                        <div class="form-group form-md-line-input has-danger">
                                                                            <div class="input-icon">
                                                                                <input type="text" class="form-control" name="department" id="department" required style="padding-left: 10px;font-weight: bolder; font-size: 18px" value="<?php echo $Dim_Emp_Dep; ?>">
                                                                                <label style="font-weight: bolder; font-size: 11px; font-family: Arial Narrow ">DEPARTMENT</label>
                                                                                <span class="help-block" style="font-size: 10px">Insert Department Name...</span>
                                                                            </div>
                                                                        </div>
                                                                    </div>

                                                                    <div class="col-md-8">
                                                                        <div class="form-group form-md-line-input has-danger">
                                                                            <div class="input-icon">
                                                                                <input type="text" class="form-control" name="Jo_title" id="Jo_title"required style="padding-left: 5px;font-weight: bolder; font-size: 17px" value="<?php echo $Dim_Emp_Job; ?>">
                                                                                <label style="font-weight: bolder; font-size: 11px; font-family: Arial Narrow ">JOB TITLE</label>
                                                                                <span class="help-block" style="font-size: 10px">Insert your job title...</span>
                                                                            </div>
                                                                        </div>
                                                                    </div>
                                                                </div> 

                                                                <div class="note note-danger">
                                                                   <h5 style="font-family: Century Gothic"> More Information Here: 
                                                                    <div class="form-group form-md-line-input has-danger">
                                                                            <div class="input-icon">
                                                                                <input type="text" class="form-control" name="Mor_Desc" id="Mor_Desc"  style="padding-left: 5px;font-weight: bolder; font-size: 20px" value="<?php echo $Dim_Emp_Info; ?>">
                                                                                <label style="font-weight: bolder; font-size: 11px; font-family: Arial Narrow ">ADDITIONAL INFORMATION ABOUT THE EMPLOYEE</label>
                                                                                <span class="help-block" style="font-size: 10px">Insert Short Description...</span>
                                                                                <!--<i class="fa fa-info"></i>-->
                                                                            </div>
                                                                    </div>
                                                                   </h5>
                                                                </div>  
                                                            </div>

                                                    <div class="modal-footer">
                                                        <button type="button" data-dismiss="modal" class="btn dark btn-outline" onclick="location.href='employees.php'">Close</button>
                                                        <a href="#modal_edit" data-toggle="modal" data-dismiss="modal" class="btn btn-danger"> SEARCH ID</a>
                                                        <input type="submit" name="insert" id="insert" value="Update Now!"  class="btn green"> 
                                                    </div>
                                                    </form>






                                                    <?php
                                                    }
                                                    ?>











                                                    </div>



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

<!--End Modal-->       

【讨论】:

    猜你喜欢
    • 2023-02-09
    • 1970-01-01
    • 2014-08-30
    • 2014-08-13
    • 2014-07-26
    • 1970-01-01
    • 1970-01-01
    • 2018-10-31
    • 1970-01-01
    相关资源
    最近更新 更多