javascript - 单击回复按钮后,我想填充引导模式中的表列

标签 javascript php jquery modal-dialog bootstrap-modal

我在下面附上了屏幕截图

enter image description here

每当我单击回复按钮时,它都会触发 Bootstrap Modal(弹出窗口),如屏幕截图所示。我面临的问题是,无论我单击哪个回复按钮,它每次都会获取第一行的值。不知道是什么问题。以下是一些代码片段。

    <table  class="table table-hover">
    <thead>
      <tr>

        <th id="nameCol">ID </th>
        <th>NAME</th>
        <th >EMAIL</th>
        <th>MOBILE</th>
        <th>MESSAGE</th>
        <th>DATE & TIME</th>
        <th>STATUS</th>
        <th>REPLY</th>
      </tr>
    </thead>
    <tbody>


<?php if( is_array( $fbrecords ) && count( $fbrecords ) > 0 ) 
foreach($fbrecords as $r) { ?>
    <tr class="idrow">
        <td id="tdname"  style="display:none;" > <?php echo $r->id; ?></td>
        <td><?php echo $r->fullname; ?></td>
        <td><?php echo $r->email; ?></td>
        <td><?php echo $r->mobile; ?></td>
        <td><?php echo $r->message; ?></td>
        <td><?php echo $r->jtime; ?></td>       

<td><button type="button" class="btn btn-sm btn-success emlbtn" data-toggle="modal" data-target="#myModal"> Reply to <?php $fname=explode(" ",$r->fullname); echo $fname[0]; ?></button>

  <!-- Modal -->
  <div class="modal fade" id="myModal" role="dialog">
    <div class="modal-dialog">

      <!-- Modal content-->
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal">&times;</button>
          <h4 class="modal-title">Reply to <?php $fname=explode(" ",$r->fullname); echo $fname[0]; ?> </h4>
        </div>
        <div class="modal-body">
        <?php echo form_open('user_authentication/new_user_registration',array('id'=>'register-form')); ?>
           <label>Recipient :</label>
          <input type="text" id="recepient" value= "<?php  echo $r->email;  ?>" style="cursor:not-allowed" disabled ></input>
          <br> </br>
          <label>Subject :</label>
          <input type="text" id="recepient" value= "Re: <?php $msg=$r->message; echo substr($msg,0,20); echo "......"; ?>"  ></input>
          <br> </br>
          <label>Message :</label>
          <textarea value="Your Message" style="margin: 0px; width: 564px; height: 131px;"></textarea>
        <br> </br>
          <?php echo form_submit('submit', 'Send Mail');
          echo form_close(); ?>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        </div>
      </div>

    </div>
  </div>

        </td>

最佳答案

Id 必须是唯一的,将 fbrecords id 附加到模态的 id 中以使其唯一

 <table  class="table table-hover">
    <thead>
      <tr>

        <th id="nameCol">ID </th>
        <th>NAME</th>
        <th >EMAIL</th>
        <th>MOBILE</th>
        <th>MESSAGE</th>
        <th>DATE & TIME</th>
        <th>STATUS</th>
        <th>REPLY</th>
      </tr>
    </thead>
    <tbody>


<?php if( is_array( $fbrecords ) && count( $fbrecords ) > 0 ) 
foreach($fbrecords as $r) { ?>
    <tr class="idrow">
        <td id="tdname"  style="display:none;" > <?php echo $r->id; ?></td>
        <td><?php echo $r->fullname; ?></td>
        <td><?php echo $r->email; ?></td>
        <td><?php echo $r->mobile; ?></td>
        <td><?php echo $r->message; ?></td>
        <td><?php echo $r->jtime; ?></td>       

<td><button type="button" class="btn btn-sm btn-success emlbtn" data-toggle="modal" data-target="#myModal-<?php echo $r->id; ?>"> Reply to <?php $fname=explode(" ",$r->fullname); echo $fname[0]; ?></button>

  <!-- Modal -->
  <div class="modal fade" id="myModal-<?php echo $r->id; ?>" role="dialog">
    <div class="modal-dialog">

      <!-- Modal content-->
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal">&times;</button>
          <h4 class="modal-title">Reply to <?php $fname=explode(" ",$r->fullname); echo $fname[0]; ?> </h4>
        </div>
        <div class="modal-body">
        <?php echo form_open('user_authentication/new_user_registration',array('id'=>'register-form')); ?>
           <label>Recipient :</label>
          <input type="text" id="recepient" value= "<?php  echo $r->email;  ?>" style="cursor:not-allowed" disabled ></input>
          <br> </br>
          <label>Subject :</label>
          <input type="text" id="recepient" value= "Re: <?php $msg=$r->message; echo substr($msg,0,20); echo "......"; ?>"  ></input>
          <br> </br>
          <label>Message :</label>
          <textarea value="Your Message" style="margin: 0px; width: 564px; height: 131px;"></textarea>
        <br> </br>
          <?php echo form_submit('submit', 'Send Mail');
          echo form_close(); ?>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        </div>
      </div>

    </div>
  </div>

        </td>

关于javascript - 单击回复按钮后,我想填充引导模式中的表列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38342536/

相关文章:

javascript - 从 video.js 获取当前时间

javascript - 无法在 mozilla firefox 中对新窗口使用 .print()

jquery - 检测用户是否滚动到嵌入 pdf 的底部

javascript - 获取并评估 javascript——为什么不工作?

jquery - 触发 anchor 链接的点击

javascript - AJAX 调用后提醒旧 session 数据

javascript - 在距页面顶部的偏移量/ anchor /可变 px 高度处显示/隐藏 div - 让 jQuery 读出 'offset/anchor' 位置

php - Yii2 - Sluggable 行为

php - Symfony Lock 组件不锁定——如何解决?

php - API 调用 JSON 到 MySQL