H_MZ 2014-09-21 17:34 采纳率: 0%
浏览 9

在引导模态中编辑数据

After searching here for a while I decided to ask my own question, even if it is similar to some others.

I'd like to pass an id to a bootstrap modal. Inside the modal, a form should be populated with data based on this id and then submitted. After submitting, the "thank you" message should also appear in the modal (or the first one should be closed and the second one opened).

I found quite some ideas here, but due to my limited understanding of jQuery and Ajax I'm unable to come up with a solution.

The buttons:

<a class="btn..." data-toggle="modal" data-target="#myModal" data-id="1">First Item</a>
<a class="btn..." data-toggle="modal" data-target="#myModal" data-id="2">Second Item</a>

The modal:

<div id="myModal" class="modal hide fade">
  <div class="modal-header">
    <button class="close" data-dismiss="modal">&times;</button>

    <!-- would be great to have data from my database already for the title -->
    <h3><?php echo "$TitleBasedOnId"; ?></h3> 

  </div>
  <div class="modal-body">            
      <div id="modalContent">

         <form id="editData" role="form" method="post">
         <!--  Form should populated with data from my MySQL database -->
         <div class="form-group">
            <div class="col-md-3">
               <label for="user">User:</label> 
               <input class="form-control" name="user" type="text" id="user" value="<?php echo '$UsernameBasedOnId'; ?>" >     
            </div>
         </div>
         ...
         <button type="submit" class="btn...">Edit User</button>
         </form>
      </div>
  </div>
  <div class="modal-footer">
    <a href="#" class="btn btn-info" data-dismiss="modal" >Close</a>
  </div>

After submitting the form, I'd like a "thank you" message in the same or a new modal.

The jQuery:

/* no idea */

Thanks for your help!

  • 写回答

1条回答 默认 最新

  • weixin_33695082 2014-09-21 17:44
    关注

    The markup for your buttons should be:

    <a class="btn..." data-toggle="modal" data-target="#myModal" data-id="1">First Item</a>
    <a class="btn..." data-toggle="modal" data-target="#myModal2" data-id="2">Second Item</a>
    <!-- The ID of the second modal is myModal2 -->
    

    The following should open the second modal when the first modal is closed (hidden.bs.modal):

    //On DOM ready
    $(function() {
    
        //set up a listen to ... sense when the first modal is hidden ... and 
        $('#myModal').on('hidden.bs.modal',function() {
    
            //...show the second modal
            $('#myModal2').modal('show');
        });
    });
    

    .....Reference ...

    评论

报告相同问题?

悬赏问题

  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 Macbookpro 连接热点正常上网,连接不了Wi-Fi。
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程
  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果