gpt4 book ai didi

javascript - 如何在超时时打开此模式?

转载 作者:行者123 更新时间:2023-11-30 15:04:37 25 4
gpt4 key购买 nike

我正在使用 CSS 和 HTML 创建模式,但想使用 jquery 在页面加载 3 秒后加载它。我很难为此找到合适的事件处理程序。执行此操作的最佳方法是什么?

模态下方

<html>
<head>
<script src="https://code.jquery.com/jquery-3.2.1.min.js"
integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
crossorigin="anonymous"></script>
</head>
<body>
<span id="about" class="target"></span>
<div class="modal">
<div class="content" style="height: 425px; width: 425px;">
<h2 style="margin-bottom: 30px;margin-top: 50px;">Welcome back!</h2>
<p style="margin-bottom: 0px;margin-top: 0px;">You left something in your cart.</p>
<p style="margin-bottom: 43px; margin-top: 0px;"> Check out today!</p>
<a class="close-btn" href="#start">X</a>
<button class="cart-button" style="width: 189px;height: 49px;">
View Cart</button>
</div>
</div>
<div class="page-container">
<p><a href="#about">Open Modal Window</a>
</div>

<script type="text/javascript" src="script.js"></script>
</body>
</html>

Javascript

window.onload = () => {
setTimeout(() => {
console.log('time');
}, 3000);

}

最佳答案

给您一个解决方案 https://jsfiddle.net/7pgrzp7d/

setTimeout(function(){
$('.modal').modal({show:true});
}, 3000);
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<span id="about" class="target"></span>
<div class="modal">
<div class="content" style="height: 425px; width: 425px;">
<h2 style="margin-bottom: 30px;margin-top: 50px;">Welcome back!</h2>
<p style="margin-bottom: 0px;margin-top: 0px;">You left something in your cart.</p>
<p style="margin-bottom: 43px; margin-top: 0px;"> Check out today!</p>
<a class="close-btn" href="#start">X</a>
<button class="cart-button" style="width: 189px;height: 49px;">
View Cart</button>
</div>
</div>
<div class="page-container">
<p><a href="#about">Open Modal Window</a>
</div>

window.onload = () => {
setTimeout(() => {
$('.modal').modal({show:true});
}, 3000);
}

希望对您有所帮助。

关于javascript - 如何在超时时打开此模式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45963426/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com