如何获取动态生成的Modal ID

时间:2017-06-01 08:46:20

标签: javascript php jquery

所以我对jquery很新,我试图获得动态生成的我的模态ID。所以这就是我的代码:

<?php
    $sql = "SELECT * FROM currentstatus";
    $res = mysql_query($sql);
     while($r = mysql_fetch_assoc($res)) {
         echo '<div class="modal fade" id="'.$r['rackName'].'" role="dialog">
      <div class="modal-dialog modal-lg" role="document">
        <div class="modal-content">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
            <h4 class="modal-title" id="myModalLabel">'.$r['rackName'].'</h4>
          </div>
          <div class="modal-body">


          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            <button type="button" class="btn btn-primary">Print</button>
          </div>
        </div>
      </div>
    </div>';
     }
  ?>

。$ [&#39; rackName&#39;]是我的动态ID

我使用以下代码调用此模态:

<a href="" data-toggle="modal" data-target="#'.$r['rackName'].'">'.$r['rackName'].'</a>

1 个答案:

答案 0 :(得分:0)

您可以捕获show事件并获取ID,如下所示:

TextView