Javascript BlackJack脚本没有在Mozilla Firefox中的按钮执行/调用“hitMe()”和“stand()”功能

问题描述:

注意:此代码适用于所有浏览器BESIDES Firefox,是的, m使用最新版本。Javascript BlackJack脚本没有在Mozilla Firefox中的按钮执行/调用“hitMe()”和“stand()”功能

注意:我只包括有问题的代码,其他一切工作正常。

当我编写下面的代码时,Firefox会加载其他一切正常。

浏览器会接受第一个按钮功能(一个按钮调用的功能),但不接受第二个或第三个按钮功能。

未提供给我的代码中包含的“优惠”按钮正常工作。它打印一个新页面。

现在当打印新页面时,出现“点击”和“站立”按钮。问题是...

...这些按钮不会像“Deal”按钮那样打印新页面。

我相信问题是要定义的功能或其内部的内容。

//**** STAND FUNCTION START DEALS DEALER CARDS **** 
function stand() 
/*Altough we have a "printCards" function, we will print the cards 
differently in the stand function. Why? When the first cards are printed, 
we have a hidden one, thus showing the hidden card in this function*/ 
{ 
dealerAcesTotal = dealerTotal; 
if (dealerAcesTotal == 22){(dealerAcesTotal = 12);} 

//KEEP DEALING CARDS TO THE DEALER WHILE THE HAND IS UNDER 17 
while (dealerAcesTotal < 17) 
{ 
randA = Math.floor((Math.random()*52)+1);//for the dealer 
dealerCards[dealerHits] = card[randA]; 
dealerTotal = (dealerTotal + dealerCards[dealerHits][3]); 
if (dealerCards[dealerHits][3] == 11){dealerAces = (dealerAces + 1);} 
dealerHits = (dealerHits + 1); 
dealerAcesTotal = dealerTotal; 
} 
//end of KEEP DEALING CARDS TO THE DEALER 



//add a new row for totals and DEAL button 
document.write("</TR><TR><TD align=center><FONT color=white><kbd>Dealer = " +  dealerAcesTotal + "</TD>"); 
document.write("<TD align=center><FONT color=white><kbd>Player = " + playerAcesTotal +  "</TD>"); 
document.write("<TD align=center><FONT color=white><kbd>BET = $" + bet + "</TD>"); 
document.write("<TD align=center><FONT color=white><kbd>" + handText + "<BR>"+ name +"'s&nbsp;Bank: $" + currentBank + "</TD>"); 
document.write("<TD align=center><FONT color=white><kbd><button onclick=\"\dealCards \(\)\">Deal</button></TD>"); 
document.write("</TR><TR>"); 
//****END OF PRINT CARDS TO FINISH HAND SCREEN 
document.close(); 
return; 
} 
//**END OF STAND FUNCTION** 

function hitMe(){playerHit();} //a sort of test for the browser... 
//****PLAYER HITS FOR A NEW CARD**** 
function playerHit() 
{ 
randA = Math.floor((Math.random()*52)+1);//for the player 
playerCards[playerHits] = card[randA]; 
playerTotal = (playerTotal + playerCards[playerHits][3]); 
if (playerCards[playerHits][3] == 11){playerAces = (playerAces + 1);} 
playerHits = (playerHits + 1); 
playerAcesTotal = playerTotal; 
// run a loop for as many aces in the hand 
//if the playerTotal is over 21 deduc 
for (i = 0; i< playerAces; i++) 
{ 
if (playerAcesTotal > 21){playerAcesTotal = (playerAcesTotal - 10);} 
} 
printCards(); 
//document.close(); 
//return; 
} 

反馈将真正赞赏。 :)

PS:我的剧本是在当前页面:http://ca1k.xkotto.com/portfolio/BLACKJACKV10.html

+0

该问题可以通过清除缓存来解决。也许试试看? –

+0

对不起,我已经尝试过这种解决方案,但迄今为止没有任何进展,但感谢您为帮助我所做的努力。 – CA1K

+0

只是检查了这一点https://support.mozilla.org/en-US/questions/751899 –

hitme挡在Firefox中不会工作,因为这些功能是不确定的,当你给他们打电话。

  • 转到您的网页在Firefox中,右键单击并选择查看源。查看你所有的代码?
  • 现在,点击优惠。当页面更改时,右键单击并再次选择查看源。看看你的所有javascript代码已经消失了吗?

这是因为您的printCards()(以及您的所有功能)错误地使用了document.write。其他浏览器如chrome是宽容的,并且会让你摆脱这种困境,但是在Firefox中,当你覆盖之前在页面上的信息时(包括javascript代码本身),你可以使用它。

您需要更改所有document.write用法使用DOM功能,而不是像document.getElementById('mydiv').innerHTML += '<td>My New Card</td>'

和你document.cleardocument.getElementById('mydiv').innerHTML ='';

你可能将不得不调整你的造型与这些变化工作也。