【问题标题】:How to add a popup window in my HTML page如何在我的 HTML 页面中添加弹出窗口
【发布时间】:2017-09-26 09:43:25
【问题描述】:

当用户单击添加到购物车按钮时,我想在我的 html 页面上添加弹出窗口。仅当 extra_option 标志为 yes 时才需要打开弹出窗口。否则它应该只是将产品添加到篮子中(在我的情况下这很好)。

这是我的代码。

<form method="post">
    <div class="col-md-12 col-sm-12 col-xs-12 pContainer">

    <div class="col-md-3 col-sm-3 col-xs-12 wrap">
        <div class="col-md-12 col-sm-12 col-xs-12 ">
            <img src="img/delivery/products/<?=$r['ImgUrl'];?>" class="img img-responsive" style="width:auto">
        </div>

    </div>

    <div class="col-md-9 col-sm-9 col-xs-12">

        <div class="col-md-9 col-sm-9 col-xs-12 pNameNdiscription">
            <h4> <b> <?=$r['ProductName']?> </b> </h4>
            <p>  <?=$r['Description']?>  </p>

        </div>

        <div class="col-md-3 col-sm-3 col-xs-12 wrap" style="float:right" >
            <div class="col-md-12 col-sm-12 col-xs-6 priceWrapper">
                <h4 style="color:black" class="pPRICE">  <b> Rs. <?=$r['Price']?> </b> </h4>
            </div>

            <div class="col-md-12 col-sm-12 col-xs-6 add2CartWrapper">

                <?php if($r['extra_option'] == 'yes') {

                // if extra_option is 'yes' when user click on 'Add To Cart' I want to show here a popup widow to select the extra option. Otherwise just add the product into the cart. 

                // I am unable to properly add a model/popup windo. 

                <input type="button" id="ad2cart" name="ad2cart" class="btn add2Cart" value="Add To Cart" onclick='updateCart("<?=$r['id']?>")'>                                    
                } 


            </div>
        </div>
    </div>
    <div class="col-sm-12 col-md-12 col-xs-12"> <hr> </div>
</div>

【问题讨论】:

  • 我不明白您的问题是什么。您只需要添加弹出窗口的代码吗? Bootstrap 内置了称为“模态”的弹出窗口。

标签: javascript jquery html popupwindow


【解决方案1】:

我想你应该尝试引导模式类:
Bootstrap Modal 是一个轻量级的多用途 JavaScript 弹出窗口,可自定义且响应迅速。它可用于在网站中显示警报弹出窗口、视频和图像。

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>

<div class="container">
  <h2>Modal Example</h2>
  <!-- Trigger the modal with a button -->
  <button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Modal</button>

  <!-- Modal -->
  <div class="modal fade" id="myModal" role="dialog">
    <div class="modal-dialog">
    
      <!-- Modal content-->
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal">&times;</button>
          <h4 class="modal-title">Modal Header</h4>
        </div>
        <div class="modal-body">
          <p>Some text in the modal.</p>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        </div>
      </div>
      
    </div>
  </div>
  
</div>

</body>
</html>

以上代码来自:LINK

以上代码说明:

  1. Bootstrap 内置了 modalmodal-dialog 类,可显示弹出窗口。
  2. 您还可以将弹出窗口分成多个部分。在上面的代码中完成。
  3. 在上面的代码中,添加了三个部分。有:页眉、正文和页脚。

根据您的需要,您可以将模态划分为任意数量的部分。

【讨论】:

  • 我想你也应该解释一下你的代码,而不是从其他地方复制粘贴。
  • 当然我会添加解释。感谢您的建议!
  • 我尝试了引导模型,但它只是在我的页面上方添加了一个黑屏。
  • 您需要调整您的父 div 以将其显示在预期的页面块上。您是否在控制台上遇到任何错误?
  • 当我点击打开模型按钮时,我只是在控制台上得到这个“[Violation] Forced reflow while execution JavaScript take 76ms”
猜你喜欢
  • 2012-03-02
  • 1970-01-01
  • 2017-07-06
  • 1970-01-01
  • 2015-10-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-08
相关资源
最近更新 更多