使用对话框模式添加和编辑数据(php mysql)

时间:2014-09-27 11:46:00

标签: php jquery ajax modal-dialog

id如何进入我的模态进行编辑?我正在使用php并且必须使用对话框模式更新数据。我怎样才能做到这一点?

 <a href="" data-toggle="modal" data-target="#myLargeModal">   
     <?=$objResult["ID"]; ?>
  <div class="modal fade" id="myLargeModal" tabindex="-1" role="dialog"   
       aria-hidden="true">         
   <input type="text" class="form-control required" name="ID"  id="ID"  
   minlength="5" required/>

    <input type="text" class="form-control required" name="Name"  
    id="Name" required>
  </div>      

2 个答案:

答案 0 :(得分:0)

<a href="" data-toggle="modal" id="modalIdOpen" data-id="<?php echo $objResult["ID"]; ?>" data-target="#myLargeModal">Open Modal</a>   

  <div class="modal fade" id="myLargeModal" tabindex="-1" role="dialog"   
       aria-hidden="true">         
   <input type="text" class="form-control required" name="ID"  id="ID"  
   minlength="5" required/>

    <input type="text" class="form-control required" name="Name"  
    id="Name" required>
  </div> 

必要的jquery脚本

<script>
$(function() {
    $(document).on('click','#modalIdOpen',function(e){
         //process here you can get id using 
         $('#ID').val($(this).data('id')); //and set this id to any hidden field in modal
     });
});
</script> 

答案 1 :(得分:0)

  you can put the id in a filed value directly 
  <a href="" data-toggle="modal" data-target="#myLargeModal"> open it  </a>

  <div class="modal fade" id="myLargeModal" tabindex="-1" role="dialog"aria-hidden="true">         
    <input type="text" name="ID" value="<?=$objResult["ID"]; ?>" />
    <input type="text" class="form-control required" name="Name"  
    id="Name" required>
  </div>