从Bootstrap模式按钮调用Ajax函数

时间:2018-05-12 23:18:59

标签: javascript ajax twitter-bootstrap

我想从bootstrap确认模式中单击一个选项后调用ajax函数。确认模式将通过函数remove(参数)

打开

任何帮助将不胜感激

function remove(parameter){
	// $("#remove-modal").modal('show');
	/*
  if( modal clicked Yes){
  ..perform ajax call using 'parameter'
  }
	*/
}
<div class="modal fade" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true" id="remove-modal">
  <div class="modal-dialog modal-sm">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel">Do you want to remove this item?</h4>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" id="modal-btn-si">Yes</button>
        <button type="button" class="btn btn-primary" id="modal-btn-no" data-dismiss="modal">No</button>
      </div>
    </div>
  </div>
</div>

1 个答案:

答案 0 :(得分:0)

我会假设将一个点击处理程序添加到&#34;是&#34;按钮,显示模态后,应该工作。类似的东西:

function remove(parameter){
    // show the dialog
    var m = $("#remove-modal").modal('show');

    // find the button in your modal, and attach an event 
    // handler to it's click event
    m.on('shown.bs.modal', function(){
        m.find('#modal-btn-si').on('click', function(e){

            // do something here...

            // When you're ready to dismiss the modal, call:
            //
            // m.modal('hide');
            //
            // Make sure this is in the callback for your
            // AJAX event, unless you want the modal dismissed
            // as soon as the button is clicked
        });
    });
}