javascript - 打开后自动刷新可折叠内容

标签 javascript jquery

我想在打开时自动刷新可折叠的内容。我怎样才能做到这一点?

我在下面有这个代码:

<!DOCTYPE html>
<html>
<head>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>

<div class="container">
  <a href="#demo" class="btn btn-info" data-toggle="collapse">Read more</a>
  <div id="demo" class="collapse">
    This needs to be refreshed everytime it shows up.
  </div>
</div>

</body>
</html>

最佳答案

如果您想在显示过程开始时触发刷新,您可以使用 show.bs.collapse 事件...

$('#demo').on('show.bs.collapse', function () {
  // Put here your code for refreshing the div content (ajax call, etc.)
});

如果您想在 div 完全可见时触发刷新(过渡已完成),那么您可以使用 shown.bs.collapse 事件...

$('#demo').on('shown.bs.collapse', function () {
  // Put here your code for refreshing the div content (ajax call, etc.)
});

如果您需要它,您可以在隐藏 div 时使用等效的事件 hide.bs.collapsehidden.bs.collapse

希望对你有帮助

关于javascript - 打开后自动刷新可折叠内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46592726/

相关文章:

javascript - 使用 jQuery 仅显示一次预加载页面

javascript - 如何调整此 Highcharts 的大小?

javascript - 使用 Javascript 连接到 Node/Express 路由

jquery - ASP.NET 服务器端表单验证 + jQuery 验证

javascript - es6 propertyIsEnumerable

javascript - Nodejs 中长时间运行的请求

javascript - 有没有办法在一个 div 容器中放置 n 个 div

javascript - ionic : clicking google maps marker to push page with NavController causes clicks on pushed page to not work

javascript - 使用 'this' 选择属性,然后与选定的 HTML 属性进行比较

javascript - Flot 线图和大型 JSON 数据 blob 未格式化为 Flot API 规范