繁体   English   中英

使用php单击打开模态的锚标记时获取模态上​​的ID

[英]Get the id on modal when click on anchor tag for open modal using php

我在单击锚标记上打开了一个模式,并使用 javascript 在输入隐藏字段中传递了 id 值,并且该隐藏字段中显示了值

    <a href="#modal2" data-toggle="modal" data-id="<?php echo $CRow['id'];?>" 
id="<?php echo $CRow['id'];?>" class="btn-floating 
waves-effect waves-light yellow modal-trigger" title="Test"></a>
        <div id="modal2" class="modal">
             <form action="lst_applicant.php" method="post" enctype="multipart/form-data">
                 <div class="modal-content">
                     <input type="hidden" id="applicantid" name="applicantid" value="" />
                     <p>Applicant Information</p>
                     <?php  
                         $applicant_detail=mysql_query("select * from tbl_useraccount where id=".$applicantid); 
                     ?>
                 </div>
                      <div class="modal-footer">
                          <button type="submit" name='save' class="btn waves-effect waves-light right modal-close">Save</button>
                      </div>
                   </form> 
               </div>

    Here is the code of javascript passing the id value in input hidden field

        <script>
            $(document).on("click", ".modal-trigger", function () {
            var myBookId = $(this).data('id');
            $(".modal-content #applicantid").val( myBookId );
          });
        </script>

问题是当我在隐藏字段中获取 id 但无法进入 php 变量时。 打开模态时如何在模态上获取id?

当我点击锚标签打开一个模态然后在模态上有一个输入隐藏字段,在这个隐藏字段中使用javascript显示每个锚标签的id值,我希望当这个隐藏字段获得id值时如何进入php变量? 我进入了 php 变量,但它不起作用

你可以实现这样的数据,你只需要在anchor modal data提供详细信息

data-id="<?php echo $CRow['id'];?>"和名称data-name="<?php echo $CRow['name'];?>"等等

 $(document).on("click", ".modal-trigger", function () { var myBookId = $(this).data('id'); var name = $(this).data('name'); var email = $(this).data('email'); $(".modal-content #applicantid").val( myBookId ); $("#appli_name").val(name); $("#appli_email").val(email); });
 <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script> <a href="#modal2" data-toggle="modal" data-id="23" data-name="John" data-email="john@gmail.com" class="btn-floating waves-effect waves-light yellow modal-trigger" title="Test">Click</a> <div id="modal2" class="modal"> <form> <div class="modal-content"> <input type="text" id="applicantid" name="applicantid" value="" /> <p>Applicant Information</p> <input type="text" id="appli_name"><br> <input type="text" id="appli_email"> </div> <div class="modal-footer"> <button type="submit" name='save' class="btn waves-effect waves-light right modal-close">Save</button> </div> </form> </div>

您不必仅在模态内获取该数据的详细信息,您可以在anchor-tag传递之前实现所有内容,例如获取id 您可以在modal传递该数据的详细信息

示例: data-name="<?php echo $CRow['name']; ?>"并在您的 javascript var name=$(this).data('name');

<a href="#modal2" data-toggle="modal" data-id="<?php echo $CRow['id'];?>" id="<?php echo $CRow['id'];?>" data-name="<?php echo $CRow['name']; ?>" class="btn-floating waves-effect waves-light yellow modal-trigger" title="Test"></a>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM