如何在引导模式上设置本地存储
How do I set local storage on a bootstrap modal?
"modal-2"id为调查打开一个模态。
我只想让这个特定的模式,在有人点击关闭按钮后,每24小时重新出现一次。
$(document).ready(function(){
var modals = ['#events'];
if (window.location.hash && ~modals.indexOf(window.location.hash)) {
$(window.location.hash).modal();
}
$("#modal-2").modal('show');
$(".modal:not(.noclose)").on("click","a",function(){
$(this).closest(".modal").modal("hide");
});
});
您可以将当前时间戳Date.now()设置为localStorage,并在每次需要决定是否显示模态时进行检查。示例代码:
var twentyFourHoursInMs = 24 * 60 * 60 * 1000;
var lastTimestamp = Number(localStorage.getItem("last-showed-at"));
var currentTimestamp = Date.now();
if ((currentTimestamp - lastTimestamp) >= twentyFourHoursInMs) {
localStorage.setItem("last-showed-at", currentTimestamp);
$("#your-modal-id").modal("show");
// Display modal once again
}
因此,这是您案例中的完整代码:
$(document).ready(function(){
var modals = ['#events'];
if (window.location.hash && ~modals.indexOf(window.location.hash)) {
$(window.location.hash).modal();
}
$(".modal:not(.noclose)").on("click","a",function(){
$(this).closest(".modal").modal("hide");
});
var currentTimestamp = Date.now();
$("#cul8a").on("hidden.bs.modal", function () {
localStorage.setItem("last-showed-at", currentTimestamp);
});
// Check for modal eligibility
var twentyFourHoursInMs = 24 * 60 * 60 * 1000;
var lastTimestamp = Number(localStorage.getItem("last-showed-at"));
if ((currentTimestamp - lastTimestamp) >= twentyFourHoursInMs) {
setTimeout(function() {
localStorage.setItem("last-showed-at", currentTimestamp);
$("#cul8a").modal("show");
}, 4000);
}
});
相关文章:
- 如何在ExtJs4应用程序上为视图、存储和模型设置自定义文件夹名称
- 为数据库存储设置角度日期格式
- jQuery 设置和获取下拉列表和输入的本地存储数据
- 设置 HTML 自定义属性与在 ID 属性中存储信息
- 根据下拉值设置本地存储
- 如何在引导模式上设置本地存储
- 如何保存从单击this.nameClass动态设置的本地存储
- AngularJS设置本地存储(object json)
- 本地存储设置初始数据
- 将本地存储项设置为值'span'标签
- 如何读取存储在图像的数据src中的URL,并在另一个img控制器的src中设置该URL onclick
- 将对象设置为Chrome存储
- 设置存储在变量中的元素的属性
- 如何将javascript变量设置为php变量并将其存储在数据库中
- 尝试使用会话存储;无法设置属性'登录'的未定义引用或null引用
- express应用程序设置存储在单独的文件中
- 将应用程序设置存储到漫游数据存储
- 如何动态设置存储dojo dgrid
- 流星css -s3错误与CollectionFS "FS.TempStore.未设置存储空间
- 设置存储在数组中的对象的属性