2017-09-26 112 views
0

我想在用戶點擊添加到購物車按鈕時在我的html頁面上添加彈出窗口。 Popupwindow只有在extra_option標誌爲yes時才需要打開。否則,它應該只是將產品添加到籃子裏(這對我來說很好)。如何在我的HTML頁面中添加彈出窗口

這是我的代碼。

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

+2

我不明白你的問題在這裏。你只需要添加一個彈出的代碼? Bootstrap內置了被稱爲「模態」的彈出窗口。 – ProEvilz

回答

0

我想你應該嘗試引導模式類:
引導莫代爾是一種輕型多用途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. 引導已建立modalmodal-dialog類,其顯示彈出窗口。
  2. 此外,您可以分段彈出窗口。這在上面的代碼中完成。
  3. 在上面的代碼中有三個部分被添加。有:標題,正文和頁腳。

根據您的需要,您可以將模態分成任意數量的部分。

+0

我想你應該解釋你的代碼,而不是複製從其他地方粘貼它。 –

+0

當然我會加上解釋。感謝您的建議! –

+0

我試過bootstrap模型,但它只是在我的頁面上方添加一個黑屏。 –

相關問題