如何在点击html链接的弹出窗口打开不同的内容
How to open different content in popups on clicking html links
我使用以下代码。我想打开不同的内容点击。
<style>
#overlay_form {
position: absolute;
border: 5px solid gray;
padding: 10px;
background: white;
width: 270px;
height: 190px;
}
#pop {
display: block;
border: 1px solid gray;
width: 65px;
text-align: center;
padding: 6px;
border-radius: 5px;
text-decoration: none;
margin: 0 auto;
}
</style>
javascript后
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
//open popup
$("#pop").click(function () {
$("#overlay_form").fadeIn(1000);
positionPopup();
});
//close popup
$("#close").click(function () {
$("#overlay_form").fadeOut(500);
});
});
//position the popup at the center of the page
function positionPopup() {
if (!$("#overlay_form").is(':visible')) {
return;
}
$("#overlay_form").css({
left: ($(window).width() - $('#overlay_form').width()) / 2,
top: ($(window).width() - $('#overlay_form').width()) / 7,
position: 'absolute'
});
}
//maintain the popup at center of the page when browser resized
$(window).bind('resize', positionPopup);
</script>
我想使用如下html
<html>
<div>
<a href="#" id="pop" >Product Overview</a>
<br/>
<div id="overlay_form" style="display:none">
<a href="#" id="close" >Close</a>
</div>
<a href="#" id="pop" >User Interface</a>
<div id="overlay_form" style="display:none">
<a href="#" id="close" >Close</a>
</div>
</div>
</html>
在点击不同的链接时,我想在弹出窗口中打开不同的内容。
不需要使用不同的id重复整个java脚本。
谢谢
首先,您不能在同一页面上使用相同的id两次,您目前在两个链接上使用#pop
, #close
和#overlay_form
,用类或不同的id更新它们。
您可以在每个a
标签中添加div
,存储您的内容,然后只需显示/隐藏此点击?
有许多方法可以做到这一点,但最简单的方法是使用现有代码,需要将许多id转换为类。像这样: