简体   繁体   English

Bootstrap模式不会在提交时关闭

[英]Bootstrap modal wont close on submit

I added a Bootstrap modal to my page. 我在页面上添加了Bootstrap模式。 Here is the code of modal div: 这是模态div的代码:

<div class="modal fade" id="myModal<?php echo $kategori['C_ID'];?>" tabindex="-1" role="dialog" aria-labelledby="myModalLabel<?php echo $kategori['C_ID'];?>">
  <div class="modal-dialog" role="document">
    <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<?php echo $kategori['C_ID'];?>">Perditeso</h4>
      </div>
      <div class="modal-body">
        <div class="form-group">
          <label for="id">ID</label>
          <input type="text" class="form-control" id="id<?php echo $kategori['C_ID'];?>" value="<?php echo $kategori['C_ID'];?>">
        </div>
        <div class="form-group">
          <label for="newname">Kategoria</label>
          <input type="text" class="form-control" id="newname<?php echo $kategori['C_ID'];?>" value="<?php echo $kategori['C_Name'];?>">
        </div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Mbyll</button>
        <button type="button" onclick="catupdate('<?php echo $kategori['C_ID'];?>')" class="btn btn-primary">Ruaj ndryshimet</button>
      </div>
    </div>
  </div>
</div>

and the catupdate function: 和catupdate函数:

function catupdate(id){
  var dataString="fshij=" + id;
  $.ajax({
    type:"post",
    url:"../functions/query.php",
    data:dataString,
    cache:false,
    success: function(html){
      $('#del').html(html);
    }
  });
  return false;
}

The function runs correctly and completes the action but it doesn't close Modal automatically. 该功能可以正常运行并完成操作,但不会自动关闭Modal。 In this case i'm tryint to edit datas there. 在这种情况下,我尝试在那编辑数据。 PHP codes are okay. PHP代码还可以。

You should close the modal programmatically after the click using : 单击后,应使用编程方式关闭模态:

$('[id^="myModal"]').modal('hide');
//OR
$('.modal').modal('hide');

Inside success function or in the beginning of your function catupdate to, eg : success函数内部或函数开始时,将catupdate为:

success: function(html){
   $('.modal').modal('hide');
   $('#del').html(html);
}

Hope this helps. 希望这可以帮助。

Use the following syntax to hide a modal: 使用以下语法隐藏模式:

$('#modalID').modal('hide');

So, in your code: 因此,在您的代码中:

function catupdate(id){
 var dataString="fshij=" + id;
  $.ajax({
    type:"post",
    url:"../functions/query.php",
    data:dataString,
    cache:false,
    success: function(html){
      $('#del').html(html);
      $('.modal:visible').modal('hide');
    }
  });
 return false;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM