1

我正在使用 Twitter Bootstrap 3,我希望有一个表单,当我提交它时,模式会出现询问我“你确定要删除人吗”有没有办法让按钮提交表单刚填完?

在其他示例中,我使用了按钮的链接,该链接将是指向 site.com/do_delete_person/person_id_18 的链接,这是 JS 文件中的 modalUrl

<a href="' + modalUrl + '" class="btn btn-primary showhouse-colour">
    <i class="icon-ok"></i> Yes
</a>
<button class="btn" data-dismiss="modal" aria-hidden="true">
    <i class="icon-ban-circle"></i> No
</button>

但为此我需要模态来提交前面的表格

4

1 回答 1

1

这是我的解决方案..我使用 window.location 将它们重定向到确认后删除 url

 <!-- Button trigger modal -->
  <a data-toggle="modal" href="#" class="delete-item btn btn-primary btn-lg" data-id="25">Launch demo modal</a>

  <!-- Modal -->
  <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
          <h4 class="modal-title">Modal title</h4>
        </div>
        <div class="modal-body">
            <input type="hidden" value="" id="delete-url"/>
           Are you sure you want to delete this item?
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
          <button type="button" class="btn btn-primary confirm">Save changes</button>
        </div>
      </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
  </div><!-- /.modal -->

jQuery(document).ready(function(){
    jQuery('.delete-item').click(function(){
        var id = jQuery(this).attr('data-id');
        var delete_url = 'http://yourdomain.com/delete/'+id;
        jQuery('#delete-url').val(delete_url);
         jQuery("#myModal").modal('show');    
    });
    jQuery('.confirm').click(function(){
        window.location = jQuery('#delete-url').val();
    });
});
于 2013-10-14T15:18:04.960 回答