【问题标题】:Bootstrap modal wont close on submit引导模式不会在提交时关闭
【发布时间】:2016-01-05 17:00:47
【问题描述】:

我在我的页面中添加了一个引导模式。这是模态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 代码没问题。

【问题讨论】:

    标签: javascript php jquery twitter-bootstrap


    【解决方案1】:

    您应该在单击后以编程方式关闭模式:

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

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

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

    希望这会有所帮助。

    【讨论】:

    • 谢谢!我使用了$('#modalID').modal('hide');,效果很好。
    【解决方案2】:

    使用以下语法隐藏模式:

    $('#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;
    }
    

    【讨论】:

    • 这个:$('#modalID').modal('hide'); 工作。谢谢!
    • @Bleron 你能接受我的回答吗?我会很高兴也很感激你。 :)
    猜你喜欢
    • 1970-01-01
    • 2016-02-02
    • 2021-08-02
    • 1970-01-01
    • 1970-01-01
    • 2015-06-27
    • 2019-07-20
    • 1970-01-01
    • 2014-06-30
    相关资源
    最近更新 更多