weixin_33733810 2014-07-17 21:36 采纳率: 0%
浏览 10

jQuery Bootstrap模态PHP

I have a form with many fields and when I click the submit button, before saving the data in my database, I would like to show a bootstrap modal popup that displays a question to the user. The user can answer "yes" or "no" to the question. In these two cases, the data will be saved in the database. The difference between the "yes" and "no" button is the action.

I get some trouble to manage with this. I know that Ajax and PHP are required but I do not really know how to do the trick.

A hand would be appreciate.

Sorry for my poor english.

  • 写回答

1条回答 默认 最新

  • ?yb? 2015-01-22 19:33
    关注

    You just need to call the modal when the submit is clicked. Then, do the ajax call based on what the user clicked.

    SOme like this:

    HTML

    //Submit Button
    <div class="form-group">
        <button id="submit" name="submit" class="btn btn-primary">Submit</button>
    </div>
    
    //Modal to ask for confirmation
    <div id="confirm" class="modal hide fade">
      <div class="modal-body">
        Are you sure?
      </div>
      <div class="modal-footer">
        <button type="button" data-dismiss="modal" class="btn btn-primary" id="yes">Yes</button>
        <button type="button" data-dismiss="modal" class="btn" id="no">No</button>
      </div>
    </div>
    

    Then, you just need to add listeners to each button and do the corresponding action.

    Javascript

    <script type="text/javascript">
    
        //If user submits, show modal.
        $("#submit").click(function() {
            showModal();
        });
    
        //If user selects Yes, do action A.
        $("#yes").click(function() {
            doAjax_A();
        });
    
        //If user selects No, do action B.
        $("#no").click(function() {
            doAjax_B();
        });
    
    </script>
    

    All thats left is to do your Ajax Call. More on: http://api.jquery.com/jquery.ajax/

    评论

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?