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