簡體   English   中英

具有Post或其他內容的Modal窗口中的JavaScript變量

[英]JavaScript Variable in Modal Window with Post or something else

我需要一點幫助。 我有一個帶有變量row_id的JavaScript。 我需要在我的引導模式窗口中的變量。 有誰能夠幫助我?

<script type="text/javascript">

 $("#myModal").modal();
 $("tr button").click(function(e) {

    e.preventDefault();
    var row_id = $(this).closest("tr").attr("data-row-id");

    alert(row_id);
  });
</script>

在這里,您會看到data-row-id。

while($erg_motor = mysqli_fetch_assoc($db_erg_motor))

                                {

                                    $body.='
                                    <tr data-row-id='.$erg_motor['id'].'>
                                        <td>'.$erg_motor['id'].'</td>
                                        <td>'.$erg_motor['motor_name'].'</td>
                                        <td>'.$erg_motor['motor_mail'].'</td>
                                        <td>'.$erg_motor['motor_fabrikat'].'</td>
                                        <td>'.$erg_motor['motor_modell'].'</td>
                                        <td>'.$erg_motor['motor_ez'].'</td>
                                        <td>'.$erg_motor['motor_km'].'</td>
                                        <td>'.$erg_motor['motor_kraftstoff'].'</td>
                                        <td>'.$erg_motor['motor_standort'].'</td>
                                        <td>'.$erg_motor['motor_mailsperre'].'</td>
                                        <td><button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">Edit</button></td>
                                    </tr>';
                                }

您需要在模態正文或標題上附加變量。

  <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
  <div class="modal-content">
    <div class="modal-header">
      <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
      <h4 class="modal-title" id="mtitle">Modal title</h4>
    </div>
    <div class="modal-body" id="mbody">
      ...
    </div>
    <div class="modal-footer">
      <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
      <button type="button" class="btn btn-primary">Save changes</button>
    </div>
  </div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->

注意id mbody和mtitle。 這是附加變量的方法

$('#mbody').html(yourvariable);

要么

 $('#mtitle').html(yourvariable)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM