注意:此代码适用于除 Firefox 之外的所有浏览器,是的,我使用的是最新版本。
注意:我只包括有问题的代码,其他一切正常。
当我编写下面的代码时,Firefox 会很好地加载其他所有内容。
浏览器将接受第一个按钮功能(由按钮调用的功能),但不接受第二个或第三个按钮功能。
我提供给您的代码中未包含的“交易”按钮可以正常工作。它打印一个新页面。
现在,当打印新页面时,会出现“Hit”和“Stand”按钮。问题是...
...按钮不会像“交易”按钮那样打印新页面。
我相信问题要么是函数的定义,要么是函数内部的内容。
//**** 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 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