日期:2014-05-16 浏览次数:20676 次
var zjl = false;
var num = 0;
var goon = true;
$(function() {
$("#scratchpad").wScratchPad({
width: 150,
height: 40,
color: "#a9a9a7",
scratchMove: function() {
num++;
if (num == 2) {
var a = "一等奖";
var b = "二等奖";
var c = "三等奖";
var e = "幸运奖";
var d = "谢谢参与";
var aa = 0.000;//一等奖的概奖
var bb = 0.001;//二等奖的概率
var cc = 0.004;//三等奖的概率
var ee = 0.996;//幸运奖的概率
var dd = 0.000;//未中奖的概率
var shows = [a, b, c,d,e];
var prob = [aa, bb, cc,dd,ee];
var len = 1000;
var probLen = [len*aa, len*bb, len*cc, len*dd, len*ee];
var ran = Math.random() * len;
for(var i = 0; i < probLen.length; i++){
var ranStart = 0;
for(var j = 0; j < i; j++){
ranStart += probLen[j];
}
var ranEnd = ranStart + probLen[i];
if(ran > ranStart && ran <= ranEnd){
var award = shows[i];
if(shows[i]!='谢谢参与')
{
zjl = true;
}
document.getElementById('prize').innerHTML = award;
$("#theAward").html(award);
<?php
$data = '{"aa":1,"bb":2,"cc":3,"dd":4}' // 这里也可以从db获取
?>
<script type="text/javascript">
var data = <?=$data ?>;
var aa = data['aa'];
var bb = data['bb'];
var cc = data['cc'];
var dd = data['dd'];
alert('aa:' + aa + ' bb:' + bb + ' cc:' + cc + ' dd:' + dd);
</script>