优惠券代码JS简单购物车
嗨,
我正试着把这个添加到我的网站上,这是一个连接到JS简单购物车的促销代码脚本,但似乎不起作用,甚至没有创建像JS被触发的动作.有没有人知道为什么没有运行该函数?
选择 | 换行 | 行号
- <div class="cartRow" id="promoCodeDiv">Promo Code: <input type="text" id="code" name="code"><button id="promoSub">Submit</button></div>
选择 | 换行 | 行号
- (function(){
- // create a cookie function
- function createCookie(name,value,days) {
- if (days) {
- var date = new Date();
- date.setTime(date.getTime()+(days*24*60*60*1000));
- var expires = "; expires="+date.toGMTString();
- } else{
- var expires = "";
- }
- document.cookie = name+"="+value+expires+"; path=/";
- }
- //This function checks to see if a cookie has been created, if so hide the promo input box
- var getCookie = function(name) {
- var start = document.cookie.indexOf(name + '=');
- if(start < 0){
- return null;
- }
- start = start + name.length + 1;
- var end = document.cookie.indexOf(';', start);
- if(end < 0){
- end = document.cookie.length;
- }
- while(document.cookie.charAt(start) == ' ') {
- start++;
- }
- return unescape(document.cookie.substring(start, end));
- }
- //if the cookie exists
- if(getCookie("promo")){
- //the ID for my promo code input box
- jQuery('#promoCodeDiv').hide();
- } else{
- jQuery('#promoCodeDiv').show();
- }
- //This is called when promo code submit button is clicked
- jQuery("#promoSub").click(function Discount() {
- //Interact with PHP file and check for valid Promo Code
- jQuery.post("/includes/discount.php", { code: jQuery('#code').val() } , function(data) {
- console.log(jQuery('#code').val());
- if (data=="0" || data=='') {
- console.log("Sorry you have entered an incorrect code.");
- }
- else {
- //create our cookie function if promo code is valid
- //create cookie for 1 day
- createCookie("promo","true",1);
- var y = (data/100);
- for(var i=0; i<simpleCart.items().length; i++){
- var itemPrice = simpleCart.items()[i].price();
- var theDiscount = itemPrice * y;
- var newPrice = itemPrice - theDiscount;
- simpleCart.items()[i].set("price", newPrice)
- }
- simpleCart.update();
- //hides the promo box so people cannot add the same promo over and over
- jQuery('#promoCodeDiv').hide();
- }
- });
- });
- })();
先谢谢你.