如何在bootstrap中传递模态中的值?

时间:2014-09-21 13:28:54

标签: php html twitter-bootstrap codeigniter

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

这就是我所做的:

<?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;
 ?>

1 个答案:

答案 0 :(得分:0)

我认为更好的方法是将数据保存在JavaScript对象中,然后当您打开Modal时,可以将这些值设置在您想要的位置。