javascript - 模态弹出重复数据

标签 javascript jquery html css

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/

相关文章:

javascript - 使用javascript在两个aspx页面之间传递数据

javascript - Reactjs 函数触发两次?

javascript - 根据背景图像删除元素

javascript - 如何使用 javascript 检测内联链接?

javascript - 滚动事件持续多长时间?

javascript - css transition 在一个元素中有效,但在第二个元素中无效

javascript - Angular 2、DataTables.net 和使用 DataTables.net-bs 的分页

javascript - jQuery UI 自动完成建议在选择时未关闭

jquery - 有没有办法对与正则表达式匹配的所有文本执行回调函数?

html - :before element in back of parent element