Javascript 如何使此弹出窗口仅在单击按钮时加载
我从一个教程中得到了这段代码,它满足了我的需要。问题是它在页面加载后立即出现,而我希望它只在按下“显示按钮”后显示Javascript 如何使此弹出窗口仅在单击按钮时加载,javascript,jquery,css,html,popup,Javascript,Jquery,Css,Html,Popup,我从一个教程中得到了这段代码,它满足了我的需要。问题是它在页面加载后立即出现,而我希望它只在按下“显示按钮”后显示 $(文档).ready(函数(){ $(“.open”)。单击(函数(){ $('.pop outer').fadeIn('slow')) }); $(“.close”)。单击(函数(){ $('.pop outer').fadeOut('slow')) }); }); .流行音乐{ 背景色:rgba(0,0,0,0.5); 位置:固定; 排名:0; 左:0; 宽度:100%;
$(文档).ready(函数(){
$(“.open”)。单击(函数(){
$('.pop outer').fadeIn('slow'))
});
$(“.close”)。单击(函数(){
$('.pop outer').fadeOut('slow'))
});
});
.流行音乐{
背景色:rgba(0,0,0,0.5);
位置:固定;
排名:0;
左:0;
宽度:100%;
身高:100%;
}
.流行音乐{
背景色:#ffffff;
宽度:500px;
高度:300px;
填充:25px;
利润率:15%;
}
显示按钮
X
这是一个自定义弹出示例
文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本
只需在
下面是完整的工作源代码
<html lang="en">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<!-- Optional theme -->
<script>
$(document).ready(function(){
$(".open").click(function(){
$('.pop-outer').fadeIn('slow')
});
$(".close").click(function(){
$('.pop-outer').fadeOut('slow')
});
});
</script>
<style>
.pop-outer{
background-color: rgba(0, 0, 0, 0.5);
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
.pop-inner{
background-color: #ffffff;
width: 500px;
height: 300px;
padding: 25px;
margin: 15% auto;
}
</style>
</head>
<body>
<button class="open">show button</button>
<div class="pop-outer" style="display:none;">
<div class="pop-inner">
<button class="close">X</button>
<h2>This is a custom pop-up exaple</h2>
<p> text text text text text text text text text text text text text text text text text text text text </p>
</div>
</div>
</body>
</html>
$(文档).ready(函数(){
$(“.open”)。单击(函数(){
$('.pop outer').fadeIn('slow'))
});
$(“.close”)。单击(函数(){
$('.pop outer').fadeOut('slow'))
});
});
.流行音乐{
背景色:rgba(0,0,0,0.5);
位置:固定;
排名:0;
左:0;
宽度:100%;
身高:100%;
}
.流行音乐{
背景色:#ffffff;
宽度:500px;
高度:300px;
填充:25px;
利润率:15%;
}
显示按钮
X
这是一个自定义弹出示例
文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本
只需在
下面是完整的工作源代码
<html lang="en">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<!-- Optional theme -->
<script>
$(document).ready(function(){
$(".open").click(function(){
$('.pop-outer').fadeIn('slow')
});
$(".close").click(function(){
$('.pop-outer').fadeOut('slow')
});
});
</script>
<style>
.pop-outer{
background-color: rgba(0, 0, 0, 0.5);
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
.pop-inner{
background-color: #ffffff;
width: 500px;
height: 300px;
padding: 25px;
margin: 15% auto;
}
</style>
</head>
<body>
<button class="open">show button</button>
<div class="pop-outer" style="display:none;">
<div class="pop-inner">
<button class="close">X</button>
<h2>This is a custom pop-up exaple</h2>
<p> text text text text text text text text text text text text text text text text text text text text </p>
</div>
</div>
</body>
</html>
$(文档).ready(函数(){
$(“.open”)。单击(函数(){
$('.pop outer').fadeIn('slow'))
});
$(“.close”)。单击(函数(){
$('.pop outer').fadeOut('slow'))
});
});
.流行音乐{
背景色:rgba(0,0,0,0.5);
位置:固定;
排名:0;
左:0;
宽度:100%;
身高:100%;
}
.流行音乐{
背景色:#ffffff;
宽度:500px;
高度:300px;
填充:25px;
利润率:15%;
}
显示按钮
X
这是一个自定义弹出示例
文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本
添加显示:无
至。弹出外部
添加显示:无代码>至。弹出外部