<div id="roll"></div><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 id="result"></div>
.demo{width:300px; margin:60px auto; text-align:center}
#roll{height:32px; line-height:32px; font-size:24px; color:#f30}
.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}
$(function(){
var _gogo;
var start_btn = $("#start");
var stop_btn = $("#stop");
start_btn.click(function(){
$.getJSON('data.php',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("data.php?action=ok",{id:mid},function(msg){
if(msg==1){
var mobile = $("#roll").html();
$("#result").append("<p>"+mobile+"</p>");
}
stop_btn.hide();
start_btn.show();
});
});
include_once('connect.php'); //连接数据库
$action = $_GET['action'];
if($action==""){ //读取数据,返回json
$query = mysql_query("select * from member where status=0");
while($row=mysql_fetch_array($query)){
$arr[] = array(
'id' => $row['id'],
'mobile' => substr($row['mobile'],0,3)."****".substr($row['mobile'],-4,4)
);
}
echo json_encode($arr);
}else{ //标识中奖号码
$id = $_POST['id'];
$sql = "update member set status=1 where id=$id";
$query = mysql_query($sql);
if($query){
echo '1';
}
}
CREATE TABLE `member` ( `id` int(11) NOT NULL auto_increment, `mobile` varchar(20) NOT NULL, `status` tinyint(1) NOT NULL default '0', PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有