如何在我的HTML页面中添加弹出窗口

时间:2017-09-26 09:43:25

标签: javascript jquery html popupwindow

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

这是我的代码。

<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>

1 个答案:

答案 0 :(得分:0)

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

&#13;
&#13;
<!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>
&#13;
&#13;
&#13;

以上代码来自:LINK

上述代码说明:

  1. Bootstrap内置modalmodal-dialog类,显示弹出窗口。
  2. 此外,您可以将弹出窗口分成几部分。在上面的代码中完成了。
  3. 在上面的代码中,添加了三个部分。有:页眉,正文和页脚。
  4. 根据您的需要,您可以将模态划分为任意数量的部分。