如何在引导程序中传递模态中的值


How can i pass values in a modal in bootstrap?

我今天正试图完成这个项目,但我发现我编写的编辑功能不起作用,因为我点击编辑的每个按钮都显示相同的值。我需要显示在一个特定模态中显示的各个数据。

以下是我所做的:

<?php 
 foreach ($allhealthlist as $row):
   echo '<tr>';
   echo '<td>' . $row['HI Name'] . '</td>';
   echo '<td>' . $row['Ownership'] . '</td>';
   echo '<td>' . $row['District'] . '</td>';
   echo '<td>' . $row['VDC'] . '</td>';
   echo '<td>' . $row['Type'] . '</td>';
   echo '<td>';
?> 

<div class="col-md-1">
  <div id="myModal" class="modal fade in" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" >
    <div class="modal-dialog">
       <div class="modal-content">
           <div class="modal-header">
             <a class="btn btn-default" data-dismiss="modal"><span class="glyphicon glyphicon-remove"></span></a>
             <h4 class="modal-title" id="myModalLabel">Heath Institute</h4>
           </div>
           <div class="modal-body">
             <div class="panel panel-default">
               <div class="panel-heading"><h3 class="panel-title"><strong>Edit Information </strong></h3></div>
               <div class="panel-body">

                <form role="form">
                 <div class="form-group">
                  <label class="hide">ID</label>
                  <input type="email" class="form-control hide" id="exampleInputEmail1" name="healtid" value="<?php echo $row['ID']; ?>">
                 </div>
                 <div class="form-group">
                  <label for="exampleInputEmail1">HI Name</label>
                  <input type="email" class="form-control" id="exampleInputEmail1" name="healthname" value="<?php echo $row['HI Name']; ?>">
                 </div>
                 <div class="form-group">
                   <label for="exampleInputEmail1">Ownership</label>
                   <input type="email" class="form-control" id="exampleInputEmail1" name="ownership" value="<?php echo $row['HI Name']; ?>">
                 </div>
                 <div class="form-group">
                   <label for="exampleInputPassword1">District</label>
                   <input type="password" class="form-control" id="exampleInputPassword1" name="district" value="<?php echo $row['HI Name']; ?>">
                 </div>
                 <div class="form-group">
                   <label for="exampleInputPassword1">VDC</label>
                    <input type="password" class="form-control" id="exampleInputPassword1" name="vdc" value="<?php echo $row['HI Name']; ?>">
                 </div>
                 <div class="form-group">
                   <label for="exampleInputPassword1">Type</label>
                   <input type="password" class="form-control" id="exampleInputPassword1" name="type" value="<?php echo $row['HI Name']; ?>">
                 </div>
              </form>
              </div>
            </div>
           </div>
           <div class="modal-footer">
              <div class="btn-group">
                <button class="btn btn-danger" data-dismiss="modal">Cancel</button>
                  <button class="btn btn-primary">Update</button>
              </div>
           </div>
         </div><!-- /.modal-content -->
        </div><!-- /.modal-dalog -->
       </div><!-- /.modal -->
       <a data-toggle="modal" href="#myModal" class="btn btn-primary" >Edit</a>
      </div>
 <?php
  echo '</td>';
  endforeach;
 ?>

在我看来,最好将数据保存在JavaScript对象中,然后当您打开Modal时,您可以在需要的地方设置这些值。