优惠券代码JS简单购物车

嗨,
我正试着把这个添加到我的网站上,这是一个连接到JS简单购物车的促销代码脚本,但似乎不起作用,甚至没有创建像JS被触发的动作.有没有人知道为什么没有运行该函数?

选择 | 换行 | 行号
  1. <div class="cartRow" id="promoCodeDiv">Promo Code: <input type="text" id="code" name="code"><button id="promoSub">Submit</button></div>
  2.  
选择 | 换行 | 行号
  1. (function(){
  2.     // create a cookie function
  3.     function createCookie(name,value,days) {
  4.         if (days) {
  5.         var date = new Date();
  6.         date.setTime(date.getTime()+(days*24*60*60*1000));
  7.         var expires = "; expires="+date.toGMTString();
  8.         } else{
  9.             var expires = "";
  10.         }
  11.         document.cookie = name+"="+value+expires+"; path=/";
  12.     }
  13.  
  14.     //This function checks to see if a cookie has been created, if so hide the promo input box
  15.     var getCookie = function(name) {
  16.         var start = document.cookie.indexOf(name + '=');
  17.         if(start < 0){
  18.             return null;
  19.         }
  20.         start = start + name.length + 1;
  21.         var end = document.cookie.indexOf(';', start);
  22.         if(end < 0){
  23.             end = document.cookie.length;
  24.         }
  25.         while(document.cookie.charAt(start) == ' ') {
  26.         start++;
  27.         }
  28.         return unescape(document.cookie.substring(start, end));
  29.     }
  30.  
  31.     //if the cookie exists
  32.     if(getCookie("promo")){
  33.         //the ID for my promo code input box
  34.         jQuery('#promoCodeDiv').hide();
  35.     }  else{
  36.         jQuery('#promoCodeDiv').show();
  37.     }
  38.  
  39.     //This is called when promo code submit button is clicked
  40.     jQuery("#promoSub").click(function Discount() {
  41.         //Interact with PHP file and check for valid Promo Code
  42.         jQuery.post("/includes/discount.php", { code: jQuery('#code').val() } , function(data) {
  43.             console.log(jQuery('#code').val());
  44.             if (data=="0" || data=='') {
  45.                 console.log("Sorry you have entered an incorrect code.");
  46.             }
  47.             else {
  48.                 //create our cookie function if promo code is valid
  49.                 //create cookie for 1 day
  50.                 createCookie("promo","true",1);
  51.                 var y = (data/100);
  52.                 for(var i=0; i<simpleCart.items().length; i++){
  53.                     var itemPrice = simpleCart.items()[i].price();
  54.                     var theDiscount = itemPrice * y;
  55.                     var newPrice = itemPrice - theDiscount;
  56.                     simpleCart.items()[i].set("price", newPrice)
  57.                 }
  58.                 simpleCart.update();
  59.                 //hides the promo box so people cannot add the same promo over and over
  60.                 jQuery('#promoCodeDiv').hide();
  61.  
  62.             }
  63.         });
  64.     });
  65. })();
  66.  

先谢谢你.

# 回答1


在第一个代码段中,您没有指定控件按钮的类型.请参阅下面的粗体

选择 | 换行 | 行号
  1. <div 
  2.   class="cartRow" 
  3.   id="promoCodeDiv"
  4. >
  5.   Promo Code: 
  6.   <input 
  7.     type="text" 
  8.     id="code" 
  9.     name="code"
  10.   >
  11.   <button 
  12.      type="button"
  13.     id="promoSub"
  14.   >
  15.     Submit
  16.   </button>
  17. </div>
  18.  

在第二部分中,你说"
//点击宣传码提交按钮时调用
JQuery("#Promote Sub").Click(函数折扣()"
我不使用jQuery,但我不知道在您的代码中您在哪里为促销提交按钮分配了任何操作.您必须在按钮上放入一个"onClick"事件,或者添加并事件Listner才能执行某些操作.

# 回答2


促销代码、折扣代码或优惠券代码是优惠码的另一个名称.促销代码类似于打印的优惠券代码,因为它们允许您通过获得特定或完整产品系列的促销折扣来节省资金.零售商可以通过使用优惠码来获得忠诚的消费者并提高销售额.制作贺卡正文>在HTML卡标题中添加.Div class="Header">div class="添加产品信息.div class="Cart-Items">HTML:将计数器放在一起.在HTML中添加定价部分.在HTML中创建结账RevelCode部分.HTML:

标签: Javascript

添加新评论