Bootstrap模态不会在提交时关闭

时间:2016-01-05 17:00:48

标签: javascript php jquery twitter-bootstrap

我在我的页面添加了一个Bootstrap模式。这是模态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>

和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;
}

该功能正常运行并完成操作,但它不会自动关闭Modal。在这种情况下,我试着在那里编辑数据。 PHP代码没问题。

2 个答案:

答案 0 :(得分:3)

您应该在点击后使用以下命令以编程方式关闭模式:

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

success函数内部或函数catupdate的开头,例如:

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

希望这有帮助。

答案 1 :(得分:1)

使用以下语法隐藏模态:

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

所以,在你的代码中:

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;
}
相关问题