单击使用PHP打开模式的锚点标记时,获取模式上的ID

时间:2018-10-31 05:26:15

标签: javascript php jquery bootstrap-modal

我在点击锚标记时打开了一个模式,并使用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变量,但无法正常工作

2 个答案:

答案 0 :(得分:2)

您可以像这样获得数据,只需在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>

答案 1 :(得分:0)

您不必仅在模态内部获取这些数据的详细信息,就可以在with open("input.pb", "rb") as f: graph_def = graph_pb2.GraphDef() graph_def.ParseFromString(f.read()) with open("input.pb", "rb") as f: graph_def = tf.GraphDef() graph_def.ParseFromString(f.read()) 传递之前完成所有工作,例如如何获取anchor-tag。您可以在id

中传递该数据的详细信息

示例:modal和您的JavaScript data-name="<?php echo $CRow['name']; ?>"

var name=$(this).data('name');