javascript - jquery ajax 关闭后发布

标签 javascript jquery ajax

我有data-id并且我想在模式隐藏/关闭后发布data-id,我该怎么做?

$(function() {
  var popup = $('#AniPopup');
  var time = $(".will-close strong");
  var closeSeconds = $("#AniPopup").attr("data-close");
  var openSeconds = $("#AniPopup").attr("data-open");
  var dataSrc = $("#AniPopup").attr("data-src");
  var dataId = $("#AniPopup").attr("data-id");
  

  setTimeout(function(e) {
    
    popup.modal('show');
    time.html(closeSeconds);
    
    setInterval(function(){
      time.html(closeSeconds);
      closeSeconds--;
      
      if(closeSeconds < 0){
        popup.modal('hide');
      }
      
    }, 1000)
    
  }, openSeconds * 1000);
  
    $.ajax({
    url: dataSrc,
    dataType: "html",
    success: function(data) {
      $(".modal-body").html(data);
    }
  });
  
  
});
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>

<div class="modal fade" id="AniPopup" tabindex="-1" role="dialog" aria-labelledby="AniPopupLabel" aria-hidden="true"  data-close="10" data-open="2" data-src="http://www.anitur.com.tr/popup/test-6-text" data-id="69">
  <div class="modal-dialog">
    <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="memberModalLabel">Popup Header</h4>
      </div>
      <div class="modal-body">
        this content loaded by ajax
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-primary" data-dismiss="modal">Kapat</button>
        <span class="will-close">will be closed after : <strong>n</strong> seconds</span>
      </div>
    </div>
  </div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

最佳答案

使用引导模式的标准事件hidden.bs.modal:

$("#AniPopup").on('hidden.bs.modal', function () {
    // do your staff here
});

关于javascript - jquery ajax 关闭后发布,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43629163/

相关文章:

jquery - 如何在 jQuery keydown 事件处理程序中检测 SHIFT 键?

jquery - 如何在ListBox中加载大量数据? ASP.NET MVC 应用程序

javascript - document.getElementById 不适用于动态 div

javascript - 我们可以在 javascript 中将通用对象转换为自定义对象类型吗?

javascript - RxJS:将历史数据与更新流相结合

javascript - 传递包含参数的回调函数?

java - 400(错误请求)错误 - 使用 JQuery AJAX 的 Spring-boot 文件上传

javascript - 选择具有相同类名的多个标签?

javascript - 如何在 es6 javascript 类中使用 async/await?

javascript - 如何在向下滚动到达另一个元素时隐藏一个元素?