PHP+Ajax结合lottery.js制作的一款微信手机端九宫格抽奖实例,抽奖完成后有收货地址添加表单出现。支持可以设置中奖概率等。
奖品列表
1 <div class="lottery_list clearfix" id="lottery"> 2 <ul> 3 <li class="lottery-unit lottery-unit-0 lottery-1"><img src="images/1.png"></li> 4 <li class="lottery-unit lottery-unit-1 lottery-2"><img src="images/2.png"></li> 5 <li class="lottery-unit lottery-unit-2 lottery-3"><img src="images/3.png"></li> 6 <li class="lottery-unit lottery-unit-7 lottery-4"><img src="images/4.png"></li> 7 8 <li><a href="javascript:void(0);"><img src="images/middle.jpg"></a></li> 9 10 <li class="lottery-unit lottery-unit-3 lottery-5"><img src="images/5.png"></li> 11 <li class="lottery-unit lottery-unit-6 lottery-6"><img src="images/6.png"></li> 12 <li class="lottery-unit lottery-unit-5 lottery-7"><img src="images/7.png"></li> 13 <li class="lottery-unit lottery-unit-4 lottery-8"><img src="images/8.png"></li> 14 </ul> 15 </div>
Ajax抽奖
1 $.post("ajax.php", function(data) { //获取奖品,也可以在这里判断是否登陆状态 2 if (data.prize_id != ‘‘ && data.prize_id != undefined) { 3 var prize_site = $(".lottery-" + data.prize_id).attr("data-ord"); 4 $("#lottery").attr("prize_site", prize_site); 5 $("#lottery").attr("prize_id", data.prize_id); 6 $("#lottery").attr("prize_name", data.prize_name); 7 $("#lottery").attr("prize_pic", data.prize_pic); 8 if (data.code == 200) { 9 $("#lottery").attr("contact_name", data.contact_name); 10 $("#lottery").attr("contact_mobile", data.contact_mobile); 11 $("#lottery").attr("contact_addr", data.contact_addr); 12 } 13 roll(); 14 click = true; 15 return false; 16 } else { 17 showLotteryTip(data.error); 18 } 19 20 }, "json")
保存收货地址
1 $.post("ajax.php", {contact_name: contact_name, contact_mobile: contact_mobile, contact_addr: contact_addr}, function(data) { 2 $("#lottery_addr_box").modal(‘hide‘); 3 if (data.code == 200) { 4 $("#tip_words").html("提交成功!"); 5 getModalBox(‘#lottery_tip‘); 6 } else { 7 showLotteryTip(data.error); 8 } 9 }, "json")
本文转自:https://www.sucaihuo.com/php/519.html 转载请注明出处!