您现在的位置是:网站首页 > 脚本编程>

jquery+php+mysql+flash实现转盘抽奖

2013-08-219832人围观
简介 现在网站上搞活动越来越多了,都有抽奖的过程,来提高网站的点击率,增加产品的知名度。下面给介绍两款抽奖的小代码,第一种是转盘式的抽奖,第二种是滚动式的抽奖。两种个有自己的优势,下面以给出下载地址。

效果图:

源码下载地址:点击下载

========================================

thinkphp+mysql+jquery 实现抽奖功能

前台代码:

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>PHP抽奖程序</title>

<script type="text/javascript" src="/Public/Js/jquery-1.9.0.min.js"></script>

<style>

.demo {

width:300px;

margin:60px auto;

text-align:center

}

#roll {

height:32px;

line-height:32px;

font-size:24px;

color:#f30;

text-align:center

}

.btn {

width:80px;

height:26px;

line-height:26px;

background:url(btn_bg.gif) repeat-x;

border:1px solid #d3d3d3;

cursor:pointer

}

#stop {

display:none

}

#result {

margin-top:20px;

line-height:24px;

font-size:16px;

text-align:center

}

.con {

text-align:center

}

</style>

</head>


<body>

<div id="roll"></div>

<div class="con">

<input type="hidden" id="mid" value="">

<p>

  <input type="button" class="btn" id="start" value="开始">

  <input type="button" class="btn" id="stop" value="停止">

</p>

</div>

<div id="result"></div>

<script language="javascript" type="text/javascript">

$(function(){ 

    var _gogo; 

    var start_btn = $("#start"); 

    var stop_btn = $("#stop"); 

     

    start_btn.click(function(){ 

        $.getJSON('/esoxue.php/Article/cqfso',function(json){ 

            if(json){ 

                var obj = eval(json);//将JSON字符串转化为对象 

                var len = obj.length; 

                _gogo = setInterval(function(){ 

                    var num = Math.floor(Math.random()*len);//获取随机数 

                    var id = obj[num]['id']; //随机id 

                    var v = obj[num]['mobile']; //对应的随机号码 

                    $("#roll").html(v); 

                    $("#mid").val(id); 

                },100); //每隔0.1秒执行一次 

                stop_btn.show(); 

                start_btn.hide(); 

            }else{ 

                $("#roll").html('系统找不到数据源,请先导入数据。'); 

            } 

        }); 

    }); 


stop_btn.click(function(){ 

        clearInterval(_gogo); 

        var mid = $("#mid").val(); 

        $.post("/esoxue.php/Article/cqfso/action/ok",{id:mid},function(msg){ 


            if(msg==1){ 

                var mobile = $("#roll").html(); 

                $("#result").append("<p>"+mobile+"</p>"); 

            } 

            stop_btn.hide(); 

            start_btn.show(); 

        }); 

    }); 


}); 

</script>

</body>

</html>

后台执行代码

<?php


class ActAction extends CommonAction {


    public function cqfs() {


        $this->display();

    }


    public function cqfso()

    {           

        $M=M('ActCqfs');

        $action = $_GET['action']; 

        if($action==""){ //读取数据,返回json 

        $list=$M->select();

        foreach ($list as $key => $value) {

            $arr[] = array( 

                'id' => $value['id'], 

                'mobile' => substr($value['mobile'],0,3)."****".substr($value['mobile'],-4,4) 

            ); 

        }

        echo json_encode($arr); 

        }else{ //标识中奖号码 

        $id = $_POST['id']; 

        $data['status']=1;

        if($M->where('id='.$id)->save($data)){ 

            echo '1'; 

        } 

    } 

    }

}

?>

数据库:

效果图:

下载地址:http://dl.vmall.com/c07h340t8x

打赏本站,你说多少就多少

本文地址:https://www.qi522.com/view/12.html

来     源:千奇博客

精彩评论

微信关注

Copyright © 2013-2019 千奇博客 保留所有权利 辽ICP备13008238号