gpt4 book ai didi

javascript - 模态弹出重复数据

转载 作者:行者123 更新时间:2023-11-28 16:07:02 26 4
gpt4 key购买 nike

HTML

<a class="btn" data-popup-open="popup-1" href="#">More Details</a>

<div class="popup" data-popup="popup-1">
<div class="popup-inner">
<h2>Wow! This is Awesome! (Popup #1)</h2>
<p>Per Serve : 5g Energy : 20kcal Protein : 0.0g Fat­Total : 0.0g Saturated &nbsp; 0.0g Carbohydrate : 0.0g Package Size : 1 x 24 x 350 g</p>
<p><a data-popup-close="popup-1" href="#">Close</a></p>
<a class="popup-close" data-popup-close="popup-1" href="#">x</a>
</div>
</div>

<a class="btn" data-popup-open="popup-1" href="#">Quick inquiry</a>

<div class="popup" data-popup="popup-1">
<div class="popup-inner">
<h2>This is the one that wont work(Popup #1)</h2>
<p>Another data that wont appear</p>
<p><a data-popup-close="popup-1" href="#">Close</a></p>
<a class="popup-close" data-popup-close="popup-1" href="#">x</a>
</div>
</div>

CSS:

/* Outer */
.popup {
width:100%;
height:100%;
display:none;
position:fixed;
top:0px;
left:0px;
background:rgba(0,0,0,0.75);
}

/* Inner */
.popup-inner {
max-width:700px;
width:90%;
padding:40px;
position:absolute;
top:50%;
left:50%;
-webkit-transform:translate(-50%, -50%);
transform:translate(-50%, -50%);
box-shadow:0px 2px 6px rgba(0,0,0,1);
border-radius:3px;
background:#fff;
}

/* Close Button */
.popup-close {
width:30px;
height:30px;
padding-top:4px;
display:inline-block;
position:absolute;
top:0px;
right:0px;
transition:ease 0.25s all;
-webkit-transform:translate(50%, -50%);
transform:translate(50%, -50%);
border-radius:1000px;
background:rgba(0,0,0,0.8);
font-family:Arial, Sans-Serif;
font-size:20px;
text-align:center;
line-height:100%;
color:#fff;
}

.popup-close:hover {
-webkit-transform:translate(50%, -50%) rotate(180deg);
transform:translate(50%, -50%) rotate(180deg);
background:rgba(0,0,0,1);
text-decoration:none;
}

jQuery:

$(function() {
//----- OPEN
$('[data-popup-open]').on('click', function(e) {
var targeted_popup_class = jQuery(this).attr('data-popup-open');
$('[data-popup="' + targeted_popup_class + '"]').fadeIn(350);

e.preventDefault();
});

//----- CLOSE
$('[data-popup-close]').on('click', function(e) {
var targeted_popup_class = jQuery(this).attr('data-popup-close');
$('[data-popup="' + targeted_popup_class + '"]').fadeOut(350);

e.preventDefault();
});
});

代码有效,但不显示第二个弹出窗口的内容。我也尝试过不同的 jquery 弹出窗口,但没有任何改变弹出窗口内的数据。单击下一步按钮时,框中的数据保持不变。我该如何解决这个问题?

最佳答案

您必须更改每个弹出窗口的 data-popup 属性,例如popup-1 用于第一个,popup-2 用于第二个:

<a class="btn" data-popup-open="popup-1" href="#">More Details</a>

<div class="popup" data-popup="popup-1">
<div class="popup-inner">
<h2>Wow! This is Awesome! (Popup #1)</h2>
<p>Per Serve : 5g Energy : 20kcal Protein : 0.0g Fat­Total : 0.0g Saturated &nbsp; 0.0g Carbohydrate : 0.0g Package Size : 1 x 24 x 350 g</p>
<p><a data-popup-close="popup-1" href="#">Close</a></p>
<a class="popup-close" data-popup-close="popup-1" href="#">x</a>
</div>
</div>

<a class="btn" data-popup-open="popup-2" href="#">Quick inquiry</a>

<div class="popup" data-popup="popup-2">
<div class="popup-inner">
<h2>This is the one that wont work(Popup #2)</h2>
<p>Another data that wont appear</p>
<p><a data-popup-close="popup-2" href="#">Close</a></p>
<a class="popup-close" data-popup-close="popup-2" href="#">x</a>
</div>
</div>

关于javascript - 模态弹出重复数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39000786/

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