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);
其中a b c d e aa bb cc dd ee 怎么能获取数据库的值呢?
------解决方案--------------------
jq不能读取数据库。
可以用php等脚本语言获取,再写入js变量.
例如:
<?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>
------解决方案--------------------
jquery不能读取数据库,而且也不安全,你可以用jquery与后端交互,或者你用nodejs也可以