原生JS实现网络彩票投注效果(2)

window.onload=function(){ var toggleMove=document.getElementById('toggleMove'); var toggleOff=true; Game.init(); move(toggleMove.parentNode,{'top':'0px'},'10'); toggleMove.onclick=function(){ if(toggleOff){ move(toggleMove.parentNode,{'top':'-242px'},'10'); this.className='close'; toggleOff = !toggleOff; }else{ move(toggleMove.parentNode,{'top':'0px'},'10'); this.className='arrow'; toggleOff = !toggleOff; } } } var Game={ 'numPos':['-63px -61px','-3px -3px','-63px -3px','-123px -3px','-183px -3px','-243px -3px','-303px -3px','-363px -3px','-423px -3px','-3px -61px'], 'oNum':document.getElementById('c_l_number'), 'personMon':document.getElementById('G_t_u_money'), 'alignArr':['百位','十位','个位'], 'btnArr':['全','大','小','奇','偶','清'], 'qishu':0, 'step':'0', 'Data':[], 'targetData':[], 'OrderArr':[], 'num':'1', 'amountX':0, 'wanfa':null, 'init':function(){ var oMode=document.getElementById('c_l_mode').getElementsByTagName('span'); var jiangjin=document.getElementById('jiangjin'); this.addInitCase1(); this.addRegulation('0'); this.control(); this.controlInput(Game.amountX); this.controlSelect(Game.num); this.getNumData(Game.step); this.empty(); for (var i=0;i < oMode.length;i++) { oMode[i].index=i; oMode[i].onclick=function(){ Game.step=this.index; for (var j=0;j < oMode.length;j++) { oMode[j].className=''; } this.className='c_l_m_first'; switch(this.index){ case 0: Game.addInitCase1(); jiangjin.innerHTML='1800'; break; case 1: Game.addInitCase1(); jiangjin.innerHTML='18'; break; case 2: Game.addInitCase2(); jiangjin.innerHTML='7.8'; break; } Game.Data.length=0; Game.addRegulation(this.index); Game.getNumData(Game.step); Game.control(); } } }, 'addInitCase1':function(){ this.oNum.innerHTML=''; for (var i=0;i < this.alignArr.length ;i++ ) { var oNum_ul=document.createElement('ul'); var oNum_ul_div=document.createElement('div'); oNum_ul_div.innerHTML=this.alignArr[i]; oNum_ul_div.className='c_l_n_align'; oNum_ul.appendChild(oNum_ul_div); for (var j=0; j < 10;j++ ) { var oNum_ul_li=document.createElement('li'); oNum_ul_li.off=true; oNum_ul_li.className='li'+i; oNum_ul_li.innerHTML=j; oNum_ul.appendChild(oNum_ul_li); } var oNum_ul_Rdiv=document.createElement('div'); for (var z=0;z < this.btnArr.length ;z++ ) { var oSpan=document.createElement('span'); oSpan.className='span'+i; oSpan.innerHTML=this.btnArr[z]; oNum_ul_Rdiv.appendChild(oSpan); } oNum_ul_Rdiv.className='c_l_n_btn'; oNum_ul.appendChild(oNum_ul_Rdiv); this.oNum.appendChild(oNum_ul); } }, 'addInitCase2':function(){ this.oNum.innerHTML=''; var init1Arr=['大','小','单','双']; for (var i=0;i < this.alignArr.length-1;i++ ) { var oNum_ul=document.createElement('ul'); var oNum_ul_div=document.createElement('div'); oNum_ul_div.innerHTML=Game.alignArr[i]; oNum_ul_div.className='c_l_n_align'; oNum_ul.appendChild(oNum_ul_div); for (var j=0; j < init1Arr.length;j++ ) { var oNum_ul_li=document.createElement('li'); oNum_ul_li.off=true; oNum_ul_li.className='li'+i; oNum_ul_li.innerHTML=init1Arr[j]; oNum_ul.appendChild(oNum_ul_li); } var oNum_ul_Rdiv=document.createElement('div'); var oSpan=document.createElement('span'); oSpan.innerHTML=this.btnArr[5]; oSpan.className='span'+i; oNum_ul_Rdiv.appendChild(oSpan); oNum_ul_Rdiv.className='c_l_n_btn'; oNum_ul.appendChild(oNum_ul_Rdiv); this.oNum.appendChild(oNum_ul); } }, 'addRegulation':function(step){ var oP=document.getElementById('c_l_s_right'); var oHide=this.getClassName(oP,'c_l_s_r_hide'); var data=[ ['从百位、十位、个位各选一个号码组成一注。','从百位、十位、个位中选择一个3位数号码组成一注,所选号码与开奖号码后3位相同,且顺序一致,即为中奖。','投注方案:345</br>开奖号码:345,即中后三直选。'], ['在百位、十位、个位任意位置上任意选择1个或1个以上号码。','从百位、十位、个位任意位置上至少选择1个以上号码,所选号码与相同位置上的开奖号码一致,即为中奖。','投注方案:百位 1</br>开奖号码:百位 1,即中定位胆百位。'], ['从百位、十位中的“大、小、单、双”中至少各选一个组成一注。','对百位和十位的“大(56789)小(01234)、单(13579)双(02468)”形态进行购买,所选号码的位置、形态与开奖号码的位置、形态相同,即为中奖。','投注方案:小双</br>开奖号码:百位与十位“小双”,即中前二大小单双。'] ]; for (var i=0;i < oHide.length ;i++ ) { oHide[i].index=i; oHide[i].innerHTML=data[step][i]; oHide[i].parentNode.onmouseover=function(ev){ ev=ev||window.event; ev.preventDefault(); for (var j=0;j< oHide.length ;j++) { oHide[j].style.display='none'; } this.children[0].style.display='block'; } } for (var i=0;i < oHide.length ;i++ ) { oHide[i].parentNode.onmouseout=function(ev){ ev=ev||window.event; ev.preventDefault(); this.children[0].style.display='none'; } } }, 'getNumData':function(step){ var addBtn=document.getElementById('c_l_b_s_addNum'); var oText=document.getElementById('c_l_data'); var amount=document.getElementById('zhushu'); var money=document.getElementById('money'); var oInput=document.getElementById('c_l_b_f_beishu'); var oUl=this.oNum.children; this.Data[step]=[]; for (var i=0;i < oUl.length ;i++ ) { this.Data[step][i]=[]; this.select(this.getClassName(oUl[i],'li'+i),this.Data[step][i]); } addBtn.onclick=function(){ oText.innerHTML=''; Game.Data[Game.Data.length]=step; Game.targetData=addNum(Game.Data); /**************************/ if(Game.targetData.length){ switch(parseInt(step)){ case 0: Game.amountX=Game.targetData.length amount.innerHTML=Game.amountX; oText.innerHTML=Game.targetData; break; case 1: Game.amountX=Game.targetData.length; amount.innerHTML=Game.amountX; for (var i=0;i < Game.targetData.length;i++ ) { oText.innerHTML+=Game.targetData[i]+'n'; } break; case 2: Game.amountX=Game.targetData.length amount.innerHTML=Game.amountX; oText.innerHTML=Game.targetData; break; } Game.wanfa=step; money.innerHTML=Game.count.accMul(Game.num,Game.amountX*2*oInput.value); }else{ money.innerHTML = '0'; amount.innerHTML = '0'; alert('请选择正确的投注方式!'); } /**************************/ } function addNum(Data){ var n=parseInt(Data[Data.length-1]); switch(n){ case 0: return getResultOne(Data[n]); break; case 1: return getResultTwo(Data[n]); break; case 2: return getResultThree(Data[n]); break; } } function getResultOne(Arr){ var newArr=[]; if(Arr[0].length > 0 && Arr[1].length > 0 && Arr[2].length > 0){ for (var i=0;i < Arr[0].length;i++ ) { for (var j=0;j< Arr[1].length;j++ ) { for (var z=0;z< Arr[2].length;z++ ) { newArr.push(Arr[0][i]+''+Arr[1][j]+''+Arr[2][z]); } } } newArr.sort(function(a,b){ return a-b; }); return newArr; }else{ return false; } } function getResultTwo(Arr){ var strArr=['百位','十位','个位']; var newArr=[]; for (var i=0;i < Arr.length ;i++ ) { if(Arr[i].length){ for (var j=0;j < Arr[i].length ;j++ ) { newArr.push(strArr[i]+' : '+Arr[i][j]) } }else{ continue; } } return newArr; } function getResultThree(Arr){ var newArr=[]; if(Arr[0].length > 0 && Arr[1].length > 0 ){ for (var i=0;i < Arr[0].length;i++ ) { for (var j=0;j< Arr[1].length;j++ ) { newArr.push(Arr[0][i]+''+Arr[1][j]); } } newArr.sort(function(a,b){ return a-b; }); return newArr; }else{ return false; } } }, 'select':function(obj,arr){ var oText=document.getElementById('c_l_data'); var three=['大','小','单','双']; for (var i=0;i<obj.length;i++ ) { obj[i].index=i; obj[i].off=true; obj[i].onclick=function(){ var oSpan=this.parentNode.getElementsByTagName('span'); for (var i=0;i < oSpan.length ;i++ ) { oSpan[i].style.background='#4a433c'; } if(this.off){ this.style.backgroundPosition='-2px -57px'; arr.push(obj[this.index].innerHTML); this.off = !this.off; }else{ this.style.backgroundPosition='-46px -57px'; if(arr.length){ for (var j=0;j<arr.length;j++ ) { if(Game.step == 2){ if(arr[j] == three[this.index]){ arr.splice(j,1); } }else{ if(arr[j] == this.index){ arr.splice(j,1); } } } } this.off = !this.off; } } } }, 'control':function(){ var oSpan,num; var controlDiv=this.getClassName(this.oNum,'c_l_n_btn'); for (var i=0;i < controlDiv.length;i++ ) { controlDiv[i].index=i; oSpan=this.getClassName(controlDiv[i],'span'+i); for (var j=0;j < oSpan.length ;j++ ) { oSpan[j].index=j oSpan[j].onclick=function(){ num=this.parentNode.index; Game.Data[Game.step][num].length=0; var oParent=this.parentNode.parentNode; var oLi=oParent.getElementsByTagName('li'); for (var z=0;z < oLi.length ;z++ ) { oLi[z].style.backgroundPosition='-46px -57px'; oLi[z].off = true; } if(Game.step != 2){ var siblings=this.parentNode.children; for (var z=0;z < siblings.length;z++ ) { siblings[z].style.background='#4a433c'; } Game.controlFn(oLi,num,this.index); } this.style.background='rgb(50,93,164)'; } } } }, 'controlFn':function(oLi,num,index){ var half=parseInt(oLi.length/2); for (var i=0;i < oLi.length ;i++ ) { switch(index) { case 0: oLi[i].style.backgroundPosition='-2px -57px'; oLi[i].off = false; Game.Data[Game.step][num].push(i); break; case 1: if(i > half-1){ oLi[i].style.backgroundPosition='-2px -57px'; oLi[i].off = false; Game.Data[Game.step][num].push(i); } break; case 2: if(i < half){ oLi[i].style.backgroundPosition='-2px -57px'; oLi[i].off = false; Game.Data[Game.step][num].push(i); } break; case 3: var n=(i*2)-1; if (n > 0 && n < oLi.length){ oLi[n].style.backgroundPosition='-2px -57px'; oLi[n].off = false; Game.Data[Game.step][num].push(n); } break; case 4: if(i*2 < oLi.length-1){ oLi[i*2].style.backgroundPosition='-2px -57px'; oLi[i*2].off = false; Game.Data[Game.step][num].push(i*2); } break; case 5: oLi[i].style.backgroundPosition='-46px -57px'; oLi[i].off = true; Game.Data[Game.step][num].length=0; break; } } }, //倍数Input 'controlInput':function(amountX){ var money=document.getElementById('money'); var oInput=document.getElementById('c_l_b_f_beishu'); var oBtn=oInput.parentNode.getElementsByTagName('span'); for (var i=0;i < oBtn.length ;i++ ) { oBtn[i].index=i; oBtn[i].onclick=function(){ if(this.index){ if(oInput.value < 9999){ oInput.value++; } }else{ if(oInput.value > 0){ oInput.value--; } } money.innerHTML=Game.count.accMul(Game.num,Game.amountX*2*oInput.value); } } oInput.addEventListener('input',function(){ if(!this.value){ this.value=0; }else{ if(this.value > 9999){ this.value=9999; }else{ this.value=parseInt(this.value); } } money.innerHTML=Game.count.accMul(Game.num,Game.amountX*2*this.value); },false); }, 'controlSelect':function(){ var oInput=document.getElementById('c_l_b_f_beishu'); var money=document.getElementById('money'); var oMode=document.getElementById('sel_mode'); oMode.addEventListener('input',function(){ switch(this.value){ case '1': Game.num=1; break; case '2': Game.num=0.1; break; case '3': Game.num=0.01; break; } money.innerHTML=Game.count.accMul(Game.num,Game.amountX*2*oInput.value); },false); }, 'empty':function(){ var oDiv=document.getElementById('c_l_number'); var emptyBtn=document.getElementById('c_l_b_deledNum'); var oText=document.getElementById('c_l_data'); var money=document.getElementById('money'); var amount=document.getElementById('zhushu'); var listUl=document.getElementById('c_r_l_ul'); var oInput=document.getElementById('c_l_b_f_beishu'); var oMode=document.getElementById('sel_mode'); var jiangjin=document.getElementById('jiangjin'); var arr=['三星直选','定位胆','大小单双']; emptyBtn.onclick=function(){ if(parseInt(money.innerHTML*999)){ var json={a:jiangjin.innerHTML,b:amount.innerHTML,c:oInput.value,d:money.innerHTML,e:Game.targetData,f:Game.num}; Game.OrderArr.push(json); var oLi=document.createElement('li'); oLi.innerHTML='<span data-step="'+Game.wanfa+'">'+arr[Game.wanfa]+'</span><span>'+amount.innerHTML+'</span><span>'+oInput.value+'</span><span>'+money.innerHTML+'</span><span>&times;</span>'; listUl.appendChild(oLi); /************************************************************/ oDiv.innerHTML=''; oText.innerHTML=''; money.innerHTML='0'; amount.innerHTML='0'; switch(parseInt(Game.step)){ case 0: Game.addInitCase1(); break; case 1: Game.addInitCase1(); break; case 2: Game.addInitCase2(); break; } Game.getNumData(Game.step); Game.control(); Game.amountX=0; if(Game.OrderArr.length){ Game.delOrder(); Game.pushIn(); } }else{ if(parseInt(amount.innerHTML)) { alert('提交注单失败,请您核实投注金额重新提交!'); }else{ alert('请您提交号码,再提交订单哟!'); } } } }, 'delOrder':function(){ var oUl=document.getElementById('c_r_l_ul'); var closeBtn=this.getClassName(oUl,'list_close'); for (var i=0;i < closeBtn.length ;i++ ) { closeBtn[i].index=i; closeBtn[i].onclick=function(){ Game.OrderArr.splice(this.index,1); this.parentNode.parentNode.removeChild(this.parentNode); } } }, 'pushIn':function(){ var supMoney=document.getElementById('supMoney'); var oPushBtn=document.getElementById('c_r_t_btn'); oPushBtn.onclick=function(){ var money=0; var pM=Game.personMon.innerHTML; if(Game.OrderArr.length){ for (var i=0;i < Game.OrderArr.length;i++ ) { money=Game.count.accAdd(money,Game.OrderArr[i].d) } if(pM > money){ if(confirm('您选择'+Game.OrderArr.length+'个注单,投注总金额'+money+'元')) { Game.personMon.innerHTML=Game.count.accSubtr(pM,money); supMoney.innerHTML='-'+money; move(supMoney,{top:'50px',opacity:'0'},'50',function(){ supMoney.innerHTML=''; this.style.cssText='top:0;opacity:1;'; }); Game.kaijiang(Game.getAward); }else{ } }else{ alert('余额不足,请充值后再进行投注!'); } }else{ alert('请您选择号码,提交注单后投注!'); } } }, 'kaijiang':function(callback){ var result=[]; var off=false; var oSpan=document.getElementById('G_t_k_num').children; var listUl=document.getElementById('c_r_l_ul'); for (var i= listUl.children.length-1 ;i >= 0; i-- ) { listUl.children[i].parentNode.removeChild(listUl.children[i]); } for (var i=0;i < oSpan.length ;i++ ) { oSpan[i].className='kaijiang'; oSpan[i].style.transitionDelay='0s'; } setTimeout(function(){ for (var i=0;i < oSpan.length ;i++ ) { var n=Math.floor(Math.random()*10); result.push(n); oSpan[i].className=''; oSpan[i].style.transitionDelay=i*0.3+'s'; oSpan[i].style.backgroundPosition=Game.numPos[n]; } return callback(result); },1500); }, 'getAward':function(res){ var issue=document.getElementById('G_t_k_t_issue'); var oBox=document.getElementById('c_r_r_box'); issue.innerHTML=addZero(Game.qishu); if(oBox.children.length == 5){ var removeObj=oBox.children[4]; removeObj.parentNode.removeChild(removeObj); } var oLi=document.createElement('li'); oLi.innerHTML='<span>'+addZero(Game.qishu)+'</span><span>'+res+'</span>'; if(oBox.children.length){ oBox.insertBefore(oLi , oBox.children[0]) }else{ oBox.appendChild(oLi); } function addZero(a){ a++; if(a < 10){ return '00'+a; }else if(a < 100){ return '0'+a; }else{ return ''+a; } } Game.qishu++; Game.setMoney(res); Game.targetData.length=0; }, 'setMoney':function(res){ var addMoney=document.getElementById('addMoney'); var regB=https://www.jb51.net/百位/,regS=https://www.jb51.net/十位/,regG=https://www.jb51.net/个位/; var bArr=[],sArr=[],gArr=[]; var san=res[2]+""+res[3]+""+res[4]; var arr=[]; arr.push(((res[2]%2?'单':'双') + (res[3]%2?'单':'双'))); arr.push(((res[2]>4?'大':'小') + (res[3]%2?'单':'双'))); arr.push(((res[2]>4?'大':'小') + (res[3]>4?'大':'小'))); var moneyAward=0; var n=null; for (var i=0;i < this.OrderArr.length ;i++ ) { n=this.OrderArr[i] switch(n.a){ case '1800': for (var z=0;z < n.e.length;z++ ) { if(san == n.e[z]){ moneyAward=this.count.accAdd( moneyAward , this.count.accMul( n.a*n.c ,n.f) ); break; } } break; case '18': var k=0; for (var z=0;z < n.e.length ;z++ ) { if( regB.test(n.e[z]) ){ if( new RegExp(res[2]).test(n.e[z]) ) { k++; continue; } }else if( regS.test(n.e[z]) ){ if( new RegExp(res[3]).test(n.e[z]) ) { k++; continue; } }else if( regG.test(n.e[z]) ){ if( new RegExp(res[4]).test(n.e[z]) ) { k++; continue; } } } moneyAward=this.count.accAdd( moneyAward , this.count.accMul( n.f, n.a*k*n.c ) ); break; case '7.8': //中奖注数初始值 var j=0; for (var z=0;z < n.e.length;z++ ) { for(var x=0;x < arr.length;x++){ if(n.e[z] == arr[x] ) { j++; continue; } } } moneyAward=this.count.accAdd( moneyAward , this.count.accMul( n.f, n.a*j*n.c ) ); break; } } if(moneyAward){ addMoney.innerHTML='+'+moneyAward; move(addMoney ,{top:'-50px',opacity:'0'},'50',function(){ addMoney.innerHTML=''; this.style.cssText='top:0;opacity:1;'; }); } this.personMon.innerHTML=this.count.accAdd(this.personMon.innerHTML,moneyAward); this.OrderArr.length=0; }, 'getClassName':function(obj,cName){ var obj= obj || document; if(obj.getElementsByClassName) { return obj.getElementsByClassName(cName); }else{ var arr=[]; var allE=obj.getElementsByTagName('*'); for (var i=0;i<allE.length;i++ ) { var allElements=allE[i].className.split(' '); for (var j=0;j<allElements.length;j++) { if(allElements[j].className==cName) { arr.push(allE[i]); break; } } } return arr; } }, 'count':{ //乘 'accMul':function(a,b) { var m=0,s1=a.toString(),s2=b.toString(); try{m+=s1.split(".")[1].length}catch(e){} try{m+=s2.split(".")[1].length}catch(e){} return Number(s1.replace(".",""))*Number(s2.replace(".",""))/Math.pow(10,m) }, //除 'accDiv':function(a,b){ var t1=0,t2=0,r1,r2; try{t1=a.toString().split(".")[1].length}catch(e){} try{t2=b.toString().split(".")[1].length}catch(e){} with(Math){ r1=Number(a.toString().replace(".","")) r2=Number(b.toString().replace(".","")) return (r1/r2)*pow(10,t2-t1); } }, //加 'accAdd':function(a,b){ var r1,r2,m; try{r1=a.toString().split(".")[1].length}catch(e){r1=0} try{r2=b.toString().split(".")[1].length}catch(e){r2=0} m=Math.pow(10,Math.max(r1,r2)) return (a*m+b*m)/m; }, //减 'accSubtr':function(a,b){ var r1,r2,m,n; try{r1=a.toString().split(".")[1].length}catch(e){r1=0} try{r2=b.toString().split(".")[1].length}catch(e){r2=0} m=Math.pow(10,Math.max(r1,r2)); n=(r1>=r2)?r1:r2; return ((a*m-b*m)/m).toFixed(n); } } }

sports-1.0-js.js

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wzjzff.html